I am trying to get an inverse power set generator, a generator that returns power sets from largest to smallest.
Here is a standard power set generator (see this question):
from itertools import chain, combinations
def powerset_generator(i):
for subset in chain.from_iterable(combinations(i, r) for r in range(len(i)+1)):
yield list(subset)
Which generates this:
[]
[1]
[2]
[3]
[1, 2]
[1, 3]
[2, 3]
[1, 2, 3]
And I'm trying for this:
[1, 2, 3]
[1, 2]
[1, 3]
[2, 3]
[1]
[2]
[3]
[]
Is there any way to reverse the generator so that it works from the back?