Created
May 19, 2015 10:49
-
-
Save ramaseshan/3b97a6ed7c05b8da64af to your computer and use it in GitHub Desktop.
Generate all the possible sublists of a list
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
def sublists(symps): | |
# sample input [1,2,3] Ex Output [[1],[2],[3],[1,2],[2,3],[1,3],[1,2,3]] | |
length = len(symps) | |
i = 0 | |
poss = [] | |
while i < length: | |
temp = [] | |
size = length - i | |
temp = [sublist for sublist in (symps[x:x+size] for x in range(len(symps) - size + 1))] | |
i = i +1 | |
#for l in temp: | |
#poss.append(temp) | |
for l in temp: | |
poss.append(l) | |
return poss | |
print sublists([1,2,3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment