[Python-ideas] Introduce collections.Reiterable

Andrew Barnert abarnert at yahoo.com
Fri Sep 20 04:34:26 CEST 2013


On Sep 19, 2013, at 18:28, Terry Reedy <tjreedy at udel.edu> wrote:

> B. Parallel: iterate the input with two iterators that march along more or less in parallel. The degenerate extreme 'for a,b in zip(iter,iter):' would be better written 'for a in iter: b = a'. If the two iterators are mostly in sync, then the second iterator is only really needed when they diverge

But this does something totally different for iterators and other iterables. For an iterator, zip(iter, iter) will get you items (0, 1), then (2, 3), then (4, 5), etc. For anything else, it'll get you items (0, 0), then (1, 1), etc. And the same basic difference holds for less extreme versions, except more obviously.

So, even if there is any useful distinction between reiterable iterators and non-reiterable here (and I don't think I see one), it pales next to the distinction between iterables that return themselves on iter and those that don't.


More information about the Python-ideas mailing list