Use recursion to print all the sublists of a given list

def withoutIndex (lst, i): return lst[ : i] + lst[i + 1 : ]def printSublists(lst): print(lst) for i in range(len(lst)): printSublists(withoutIndex(lst, i))printSublists([1, 2, 3])

NM
Answered by Nikolai M. Python tutor

1475 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Explain why creating a list of several instances of one element using something like my_list = [a] * 5 can result in strange behaviour


What can I do with Python?


Generate an array of integers from 0 to 99 and split it into two smaller arrays. Each smaller array will contain half of the original.


Ask the user for a number and output the smallest divisor, bigger than one, for the inputted number. Output "Prime" if the number is a prime number.


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences