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])

Answered by Nikolai M. Python tutor

1416 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Describe both For-loops and While-loops and explain how you can simulate the effect of a for loop with a while loop with an example.


How can you take a list of numbers and add 3 to every number in the list using only one line of code?


Write a function that takes a string, and outputs that string formatted in camelcase. (alternating upper and lower case for each character, e.g. cAmElCaSe)


What is the difference between a float and an integer variable type?


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences