Skip to content

Instantly share code, notes, and snippets.

@jml
Created March 8, 2013 09:43
Show Gist options
  • Save jml/5115355 to your computer and use it in GitHub Desktop.
Save jml/5115355 to your computer and use it in GitHub Desktop.
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment