Skip to content

Commit 3577176

Browse files
committed
-
1 parent bdf7bca commit 3577176

File tree

5 files changed

+12
-37
lines changed

5 files changed

+12
-37
lines changed

source_py3/python_toolbox/combi/perm_space.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,15 +532,6 @@ def __getitem__(self, i):
532532
__hash__ = lambda self: hash(self._reduced)
533533

534534

535-
def __contains__(self, item):
536-
try:
537-
self.index(item)
538-
except ValueError:
539-
return False
540-
else:
541-
return True
542-
543-
544535
def index(self, perm):
545536
'''Get the index number of permutation `perm` in this space.'''
546537
if not isinstance(perm, collections.Iterable):

source_py3/python_toolbox/combi/product_space.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ def __getitem__(self, i):
6262
__eq__ = lambda self, other: (isinstance(other, ProductSpace) and
6363
self._reduced == other._reduced)
6464

65-
def __contains__(self, given_sequence):
66-
try:
67-
self.index(given_sequence)
68-
except ValueError:
69-
return False
70-
else:
71-
return True
72-
7365
def index(self, given_sequence):
7466
if not isinstance(given_sequence, collections.Sequence) or \
7567
not len(given_sequence) == len(self.sequences):

source_py3/python_toolbox/combi/selection_space.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,24 @@ def __getitem__(self, i):
8484

8585
_reduced = property(lambda self: (type(self), self.sequence))
8686
__hash__ = lambda self: hash(self._reduced)
87-
87+
__bool__ = lambda self: bool(self.length)
8888
__eq__ = lambda self, other: (isinstance(other, SelectionSpace) and
8989
self._reduced == other._reduced)
9090

91-
def __contains__(self, given_iterable):
92-
try:
93-
self.index(given_iterable)
94-
except ValueError:
95-
return False
96-
else:
97-
return True
98-
99-
def index(self, given_iterable):
100-
if not isinstance(given_iterable, collections.Iterable):
91+
def index(self, selection):
92+
'''Find the index number of `selection` in this `SelectionSpace`.'''
93+
if not isinstance(selection, collections.Iterable):
10194
raise ValueError
10295

103-
given_iterable_set = set(given_iterable)
96+
selection_set = set(selection)
10497

105-
if not given_iterable_set <= self._sequence_set:
98+
if not selection_set <= self._sequence_set:
10699
raise ValueError
107100

108101
return sum((2 ** i) for i, item in enumerate(reversed(self.sequence))
109-
if item in given_iterable_set)
102+
if item in selection_set)
110103

111104

112-
__bool__ = lambda self: bool(self.length)
113105

114106

115107

source_py3/python_toolbox/sequence_tools/cute_range.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,6 @@ def __len__(self):
203203
# Sadly Python doesn't allow infinity or floats here.
204204
return self.length if isinstance(self.length, numbers.Integral) else 0
205205

206-
def __contains__(self, i):
207-
try: self.index(i)
208-
except ValueError: return False
209-
else: return True
210-
211206
def index(self, i):
212207
from python_toolbox import math_tools
213208
if not isinstance(i, numbers.Number):

source_py3/python_toolbox/sequence_tools/misc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ def __init__(self, slice_, iterable_or_length=None, offset=0):
402402
class CuteSequenceMixin(misc_tools.AlternativeLengthMixin):
403403
def take_random(self):
404404
return self[random.randint(0, get_length(self))]
405+
def __contains__(self, item):
406+
try: self.index(item)
407+
except ValueError: return False
408+
else: return True
409+
405410

406411

407412
class CuteSequence(CuteSequenceMixin, collections.Sequence):

0 commit comments

Comments
 (0)