Skip to content

Instantly share code, notes, and snippets.

@ishankhare07
Last active January 5, 2016 10:14
Show Gist options
  • Save ishankhare07/fb586cf159e5c4d18c2d to your computer and use it in GitHub Desktop.
Save ishankhare07/fb586cf159e5c4d18c2d to your computer and use it in GitHub Desktop.
return a list of subsets
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)
@ishankhare07
Copy link
Author

see output here -> https://repl.it/Bbi1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment