Skip to content

Commit 8810e43

Browse files
committed
-
1 parent 3f35447 commit 8810e43

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

source_py2/python_toolbox/collection_tools.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,25 @@
1111

1212

1313
@nifty_collections.LazyTuple.factory
14-
def get_all_contained_counters(counter):
14+
def get_all_contained_counters(counter, use_lazy_tuple=True):
15+
'''
16+
Get all counters that are subsets of `counter`.
17+
18+
This means all counters that have amounts identical or smaller than
19+
`counter` for each of its keys.
20+
21+
If `use_lazy_tuple=True` (default), value is returned as a `LazyTuple`, so
22+
it may be used both by lazily iterating on it *and* as a tuple. Otherwise
23+
an iterator is returned.
24+
'''
25+
iterator = _get_all_contained_counters(counter)
26+
if use_lazy_tuple:
27+
return nifty_collections.LazyTuple(iterator)
28+
else:
29+
return iterator
30+
31+
32+
def _get_all_contained_counters(counter, use_lazy_tuple=True):
1533
assert isinstance(counter, collections.Counter)
1634
counter_type = type(counter)
1735
keys, amounts = zip(

source_py3/python_toolbox/collection_tools.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,25 @@
1111

1212

1313
@nifty_collections.LazyTuple.factory
14-
def get_all_contained_counters(counter):
14+
def get_all_contained_counters(counter, use_lazy_tuple=True):
15+
'''
16+
Get all counters that are subsets of `counter`.
17+
18+
This means all counters that have amounts identical or smaller than
19+
`counter` for each of its keys.
20+
21+
If `use_lazy_tuple=True` (default), value is returned as a `LazyTuple`, so
22+
it may be used both by lazily iterating on it *and* as a tuple. Otherwise
23+
an iterator is returned.
24+
'''
25+
iterator = _get_all_contained_counters(counter)
26+
if use_lazy_tuple:
27+
return nifty_collections.LazyTuple(iterator)
28+
else:
29+
return iterator
30+
31+
32+
def _get_all_contained_counters(counter, use_lazy_tuple=True):
1533
assert isinstance(counter, collections.Counter)
1634
counter_type = type(counter)
1735
keys, amounts = zip(

0 commit comments

Comments
 (0)