Skip to content

Instantly share code, notes, and snippets.

@kalda341
Created August 3, 2019 04:42
Show Gist options
  • Select an option

  • Save kalda341/82dee0380da5afeb771d8d42e4c6f78c to your computer and use it in GitHub Desktop.

Select an option

Save kalda341/82dee0380da5afeb771d8d42e4c6f78c to your computer and use it in GitHub Desktop.
def head(x):
return x[0]
def tail(x):
return x[1:]
def powerset(x):
if x == []:
return [[]]
else:
tail_set = powerset(tail(x))
return tail_set + [[head(x)] + s for s in tail_set]
print(powerset([1, 2, 3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment