Skip to content

Instantly share code, notes, and snippets.

@samarthbhargav
Created December 4, 2014 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samarthbhargav/74b08189a5d1203b845e to your computer and use it in GitHub Desktop.
Save samarthbhargav/74b08189a5d1203b845e to your computer and use it in GitHub Desktop.
Recursive generation of a power set
# as seen in 6.00.2x, Week 6, Lecture 1, Video 4
def powerset(iterable):
if len(iterable) == 0:
return [[]]
smaller = powerset(iterable[1:])
withElem = []
for s in smaller:
withElem.append( s + [iterable[0]])
return withElem + smaller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment