iterators
operationcounter.iterators
operationcounter.iterators module.
Iterators.
exception_generator(ex: type[Exception] = IndexError) -> Generator[Never]
Raise the provided exception on the first yield.
>>> sum(islice(chain([1, 2, 3], exception_generator()), 3))
6
>>> sum(islice(chain([1, 2, 3], exception_generator()), 4))
Traceback (most recent call last):
...
IndexError
Used to ensure that iteration doesn't go too far.
Source code in operationcounter\iterators.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
group_ordinal(*iterables: Iterable[Any]) -> tuple[Any, ...]
Group elements of iterables by their ordinal.
>>> iterables = (1, 2, 3), [4, 5, 6, 7], {8}
>>> list(group_ordinal(*iterables))
[(1, 4, 8), (2, 5), (3, 6), (7,)]
The elements are grouped in the same order as their iterables (stable).
References
Source code in operationcounter\iterators.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |