Powersets of a list?

Walter Vannini walterv at jps.net
Fri May 25 14:51:45 EDT 2001


This also seems to do it:

def PowerSet2( PowerSetSoFar, element):
    return [i+j for i in PowerSetSoFar for j in [ [], [element] ] ]

def PowerSet( set ):
    return reduce (PowerSet2, set, [ [] ])

print PowerSet([1,2,3])

Walter.



More information about the Python-list mailing list