Created
September 9, 2019 15:41
-
-
Save atul-chaudhary/7834fa2a175303a5b4053cc2b2535caf to your computer and use it in GitHub Desktop.
Program to print all subset of a list in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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