Last active
January 5, 2016 10:14
-
-
Save ishankhare07/fb586cf159e5c4d18c2d to your computer and use it in GitHub Desktop.
return a list of subsets
This file contains hidden or 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 subsets(not_selected, selected=[]): | |
if not not_selected: | |
return [selected] | |
else: | |
current_element = not_selected[0] | |
return ( | |
subsets(not_selected[1:], selected) + \ | |
subsets(not_selected[1:], selected + [current_element]) | |
) | |
for x in subsets([1,2,3]): | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see output here -> https://repl.it/Bbi1