shapiq.utils.powersetΒΆ
- shapiq.utils.powerset(iterable, min_size=0, max_size=None)[source]ΒΆ
Return a powerset of an iterable as tuples with optional size limits.
- Parameters:
iterable (
Iterable[TypeVar(T,int,str)]) β An iterable (e.g., list, set, etc.) from which to generate the powerset.min_size (
int) β Minimum size of the subsets. Defaults to 0 (start with the empty set).max_size (
int|None) β Maximum size of the subsets. Defaults to None (all possible sizes).
- Returns:
Powerset of the iterable.
- Return type:
Example
>>> list(powerset([1, 2, 3])) [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
>>> list(powerset([1, 2, 3], min_size=1)) [(1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
>>> list(powerset([1, 2, 3], max_size=2)) [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3)]
>>> list(powerset(["A", "B", "C"], min_size=1, max_size=2)) [('A',), ('B',), ('C',), ('A', 'B'), ('A', 'C'), ('B', 'C')]