Use the position of 1
in bites to calculate all the possibilities of combinations in a list.
0 0 0 0 0
to indicate all the items’ positions, and 1
can be every position in the bits. All the combinations should be the Powerset we want to, then use >>
to check every combination’s position whether it is 1 or not.1 | def powerSet(items): |
Use itertools.combinations
to calculate r length subsequences of elements, then iterate with different length.
combinations
is a little complicated, added some notations to help me to understand.1 | from itertools import chain |