4 ms·
Iterators can be shared in Python e.g., here's a well-known grouper recipe (traverse `it` iterator in chunks of `N` items each): zip(*[it]*N) Example:
by d0mine 3y ago
Iterators can be shared in Python e.g.,
here's a well-known grouper recipe (traverse `it` iterator in chunks of `N` items each):
zip(*[it]*N)
Example:
>>> L = [1, 2, 3, 4]
>>> *zip(*[iter(L)]*2),
((1, 2), (3, 4))
Here's the single result of the iter() call is shared. The purpose is to show that iterator can be shared in principle (ignore other aspects of the code).