CombSpace and Comb¶CombSpace¶CombSpace(iterable_or_length, n_elements, *, slice_=None, perm_type=None)¶A space of combinations.
This is a subclass of PermSpace; see its documentation for more
details.
Each item in a CombSpace is a Comb, i.e. a combination.
This is similar to itertools.combinations(), except it offers far, far
more functionality. The combinations may be accessed by index number, the
combinations can be of a custom type, the space may be sliced, etc.
Here is the simplest possible CombSpace:
>>> comb_space = CombSpace(4, 2)
<CombSpace: 0..3, n_elements=2>
>>> comb_space[2]
<Comb, n_elements=2: (0, 3)>
>>> tuple(comb_space)
(<Comb, n_elements=2: (0, 1)>, <Comb, n_elements=2: (0, 2)>,
<Comb, n_elements=2: (0, 3)>, <Comb, n_elements=2: (1, 2)>,
<Comb, n_elements=2: (1, 3)>, <Comb, n_elements=2: (2, 3)>)
The members are Comb objects, which are sequence-like objects that
have extra functionality. (See documentation of Comb and its base
class Perm for more info.)
Comb¶Comb(perm_sequence, perm_space=None)¶A combination of items from a CombSpace.
In combinatorics, a combination is like a permutation except with no order.
In the combi package, we implement that by making the items in Comb be
in canonical order. (This has the same effect as having no order because
each combination of items can only appear once, in the canonical order,
rather than many different times in many different orders like with
Perm.)
Example:
>>> comb_space = CombSpace('abcde', 3)
>>> comb = Comb('bcd', comb_space)
>>> comb
<Comb, n_elements=3: ('a', 'b', 'c')>
>>> comb_space.index(comb)
6