Skip to content

Instantly share code, notes, and snippets.

@atul-chaudhary
Created September 9, 2019 15:41
Show Gist options
  • Save atul-chaudhary/7834fa2a175303a5b4053cc2b2535caf to your computer and use it in GitHub Desktop.
Save atul-chaudhary/7834fa2a175303a5b4053cc2b2535caf to your computer and use it in GitHub Desktop.
Program to print all subset of a list in python
lst=[1,2,3,4]
lst1=[]
lst1.append([])
for i in range(len(lst)):
tmp_lst=[]
for j in range(i+1,len(lst)+1):
tmp_lst=lst[i:j]
lst1.append(tmp_lst)
print(lst1)
#here is the output
[[], [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2], [2, 3], [2, 3, 4], [3], [3, 4], [4]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment