Skip to content

Instantly share code, notes, and snippets.

@bemasher
Created May 1, 2009 03:38
Show Gist options
  • Save bemasher/104855 to your computer and use it in GitHub Desktop.
Save bemasher/104855 to your computer and use it in GitHub Desktop.
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