Skip to content

Instantly share code, notes, and snippets.

@michaelkrisper
Created May 16, 2013 23:25
Show Gist options
  • Save michaelkrisper/5595918 to your computer and use it in GitHub Desktop.
Save michaelkrisper/5595918 to your computer and use it in GitHub Desktop.
Python: Powerset (Potenzmenge)
# Compute the Powerset of a list
# items = [1, 2]
# powerset = [[], [1], [2], [1, 2]]
import itertools
items = [1, 2, 3, 4]
powerset = [x for length in range(len(items)+1) for x in itertools.combinations(items, length)]
@halers
Copy link

halers commented Jul 27, 2018

Nice!

@TPeschel
Copy link

TPeschel commented Nov 3, 2018

brillant!

@kernbeisser
Copy link

just what i needed! awesome!

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