programming-examples/python/List/Python program to generate all sublists of a list.py
2019-11-15 12:59:38 +01:00

15 lines
352 B
Python

def sub_lists(my_list):
subs = [[]]
for i in range(len(my_list)):
n = i+1
while n <= len(my_list):
sub = my_list[i:n]
subs.append(sub)
n += 1
return subs
l1 = [10, 20, 30, 40]
l2 = ['X', 'Y', 'Z']
print(sub_lists(l1))
print(sub_lists(l2))