Skip to content

Commit 2230c69

Browse files
committed
-
1 parent 235f267 commit 2230c69

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

python_toolbox/cute_iter_tools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,8 @@ def make_false_iterator():
243243
except StopIteration:
244244
break
245245

246-
return (make_true_iterator(), make_false_iterator())
246+
return (make_true_iterator(), make_false_iterator())
247+
248+
249+
250+

python_toolbox/sequence_tools.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
def are_equal_regardless_of_order(seq1, seq2):
1818
'''
19+
blocktododoc
1920
Return whether the two sequences are equal in the elements they contain,
2021
regardless of the order of the elements.
2122
@@ -261,18 +262,22 @@ def to_tuple(single_or_sequence, item_type=None, item_test=None):
261262
return tuple(single_or_sequence)
262263

263264

264-
def pop_until(sequence, condition=None):
265+
def pop_until(sequence, condition=bool):
265266
'''
267+
blocktododoc
268+
266269
Propagates whatever error is raised on popping the sequence.
267270
'''
268-
condition = condition or bool
269271
while True:
270272
item = sequence.pop()
271273
if condition(item):
272274
return item
273275

274276

275-
277+
def get_recurrences(sequence):
278+
return {item: n_recurrences for item, n_recurrences in
279+
Counter(sequence).most_common() if n_recurrences >= 2}
280+
276281
### Not using now, might want in future:
277282

278283
#def heads(sequence, include_empty=False, include_full=True):
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2009-2013 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
from python_toolbox.sequence_tools import get_recurrences
5+
6+
7+
def test():
8+
assert get_recurrences([]) == get_recurrences(xrange(10)) == \
9+
get_recurrences(xrange(100)) == {}
10+
assert get_recurrences((1, 1, 1, 2, 2, 3)) == {1: 3, 2: 2,}

0 commit comments

Comments
 (0)