forked from cool-RR/python_toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomb_space.py
More file actions
44 lines (31 loc) · 1.38 KB
/
comb_space.py
File metadata and controls
44 lines (31 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from .perm_space import PermSpace
class CombSpace(PermSpace):
'''
A space of combinations.
Every item in a `CombSpace` is a `Comb`.
'''
def __init__(self, iterable_or_length, n_elements,
slice_=None, _domain_for_checking=None,
_degrees_for_checking=None):
PermSpace.__init__(
self, iterable_or_length=iterable_or_length, n_elements=n_elements,
is_combination=True, slice_=slice_,
domain=_domain_for_checking, degrees=_degrees_for_checking
)
def __repr__(self):
sequence_repr = repr(self.sequence)
if len(sequence_repr) > 40:
sequence_repr = \
''.join((sequence_repr[:35], ' ... ', sequence_repr[-1]))
return '<%s: %s%s%s>%s' % (
type(self).__name__,
sequence_repr,
(', n_elements=%s' % (self.n_elements,)) if self.is_partial
else '',
(', fixed_map=%s' % (self.fixed_map,)) if self.is_fixed else '',
('[%s:%s]' % (self.slice_.start, self.slice_.stop)) if
self.is_sliced else ''
)
from .comb import Comb
# Must set this after-the-fact because of import loop:
CombSpace.perm_type = Comb