Generator tools
utilz.genz
Tools for working with generators. Also see the toolz
library!
combine_gens(*iterables)
Combine multiple generators into a single generator based on every unique combination of their elements. This is equivalent to a series of nested for loops just like itertools.product(). But unlike itertools.product doesn't exhaust each generator before combining them.
Examples:
>>> # This
>>> for aa in a:
>>> for bb in b:
>>> for cc in c:
>>> func(aa, bb, cc)
>>> # Becomes this
>>> for aa, bb, cc in combine_gens(a, b, c):
>>> func(aa, bb, cc)
Yields:
Type | Description |
---|---|
generator |
Source code in utilz/genz.py
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 |
|
make_gen(iterable)
Turn any iterable into a generator
Source code in utilz/genz.py
6 7 8 |
|