Given a set
{0, 1, 2, 3}
How can I produce the subsets:
[set(), {0}, {1}, {2}, {3}, {0, 1}, {0, 2}, {0, 3}, {1, 2}
Use function powerset() from package more_itertools.
Yields all possible subsets of the iterable
>>> list(powerset([1, 2, 3])) [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
If you want sets, use:
list(map(set, powerset(iterable)))