hbutils.reflection.iter¶
nested_for¶
-
hbutils.reflection.iter.
nested_for
(*iters: Iterable[_ItemType]) → Iterator[Tuple[_ItemType, …]][source]¶ Nested for based on several iterators.
- Parameters:
iters – Iterators to build this nested for loop.
- Returns:
Nested for loop iteration.
- Examples::
>>> from hbutils.reflection import nested_for >>> for a, r, b in nested_for( ... range(1, 3), ... ['a', 'b'], ... map(lambda x: x ** 2, range(1, 4)) ... ): >>> print(a, r, b) 1 a 1 1 a 4 1 a 9 1 b 1 1 b 4 1 b 9 2 a 1 2 a 4 2 a 9 2 b 1 2 b 4 2 b 9
progressive_for¶
-
hbutils.reflection.iter.
progressive_for
(iterable: Iterable[_ItemType], n: int, offset: int = 1) → Iterator[Tuple[_ItemType, …]][source]¶ Progressive for based on one given
iterable
.- Parameters:
iterable – Iterable object for this loop.
n – Depth of this loop.
offset – Offset of this loop, default is
1
which means the first value in the next level will be the one after the above level.
- Returns:
Progressive for loop iteration.
- Examples::
>>> from hbutils.reflection import progressive_for >>> for a, b in progressive_for(range(4), 2): ... print(a, b) 0 1 0 2 0 3 1 2 1 3 2 3 >>> for a, b in progressive_for(range(4), 2, 0): ... print(a, b) 0 0 0 1 0 2 0 3 1 1 1 2 1 3 2 2 2 3 3 3 >>> for a, b, c in progressive_for(range(5), 3): ... print(a, b, c) 0 1 2 0 1 3 0 1 4 0 2 3 0 2 4 0 3 4 1 2 3 1 2 4 1 3 4 2 3 4 >>> for a, b, c in progressive_for(range(5), 3, 2): ... print(a, b, c) 0 2 4