jaxvacua.util.subsets

Contents

jaxvacua.util.subsets#

subsets(iterable, n, as_list=True)#

All size-n subsets of an iterable. Thin wrapper around itertools.combinations with an optional list-eager flag.

Parameters:
  • iterable (Iterable) – The source elements.

  • n (int) – Size of each output subset.

  • as_list (bool) – If True (default) materialise the result as a list; otherwise return the itertools.combinations object directly.

Returns:

list or itertools.combinations – All size-n subsets.

Return type:

Union[list, combinations]

Example

subsets(range(4), n=2)
# [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]