jaxvacua.util.subsets#
- subsets(iterable, n, as_list=True)#
All size-
nsubsets of an iterable. Thin wrapper arounditertools.combinationswith an optional list-eager flag.- Parameters:
iterable (
Iterable) – The source elements.n (
int) – Size of each output subset.as_list (
bool) – IfTrue(default) materialise the result as alist; otherwise return theitertools.combinationsobject directly.
- Returns:
list or itertools.combinations – All size-
nsubsets.- Return type:
Union[list,combinations]
Example
subsets(range(4), n=2) # [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]