Skip to content

Instantly share code, notes, and snippets.

@seungjin
Forked from bemasher/Python PowerSet.py
Created May 3, 2009 18:17
Show Gist options
  • Save seungjin/106098 to your computer and use it in GitHub Desktop.
Save seungjin/106098 to your computer and use it in GitHub Desktop.
PowerSet.py
#!/usr/bin/env python
# PowerSet program
def PowerSet(base):
power_set = []
b = len(base)
map(lambda g: power_set.append(map(lambda x: base[x],
filter(lambda x: g[x], range(0, b)))),
map(lambda value: map(lambda x: (value >> x) & 1, range(b - 1, -1, -1)),
map(lambda value: value ^ (value / 2), range(0, 2**b))))
return power_set
print PowerSet([1,2,3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment