Skip to content

Commit 1fb302d

Browse files
committed
-
1 parent 7e4929f commit 1fb302d

File tree

3 files changed

+6
-79
lines changed

3 files changed

+6
-79
lines changed

source_py3/python_toolbox/logic_tools.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def all_equal(iterable, exhaustive=False):
2525
# work for unhashables.
2626

2727
if exhaustive is True:
28-
pairs = sequence_tools.combinations(list(iterable), 2)
28+
from python_toolbox import combi
29+
items = tuple(iterable)
30+
pairs = tuple(
31+
tuple(items[i] for i in comb) for comb in
32+
combi.CombSpace(len(items), min(2, len(items)))
33+
)
2934
else: # exhaustive is False
3035
pairs = cute_iter_tools.iterate_overlapping_subsequences(iterable)
3136

source_py3/python_toolbox/sequence_tools/misc.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,6 @@ def flatten(iterable):
4848
return []
4949

5050

51-
def combinations(sequence, n=None, start=0):
52-
'''
53-
Iterate over combinations of items from the sequence.
54-
55-
`n` specifies the number of items. (Use `None` for all possible sizes
56-
together.) `start` specifies the index number of the member from which to
57-
start giving combinations. (Keep the default of `start=0` for doing the
58-
whole sequence.)
59-
60-
Example:
61-
62-
`combinations([1, 2, 3, 4], n=2)` would be, in list form: `[[1, 2], [1, 3],
63-
[1, 4], [2, 3], [2, 4], [3, 4]]`.
64-
'''
65-
66-
if n is None:
67-
length = len(sequence) - start
68-
iterators = (combinations(sequence, n=i, start=start) for i
69-
in range(1, length + 1))
70-
yield from itertools.chain(*iterators)
71-
72-
elif n == 1:
73-
for thing in itertools.islice(sequence, start, None):
74-
yield [thing]
75-
else:
76-
assert n > 1
77-
for (i, thing) in itertools.islice(enumerate(sequence), start, None):
78-
for sub_result in combinations(sequence, n - 1, start=(i + 1)):
79-
yield [thing] + sub_result
80-
81-
8251
class NO_FILL_VALUE:
8352
'''
8453
Sentinel that means: Don't fill last partition with default fill values.

source_py3/test_python_toolbox/test_sequence_tools/test_combinations.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)