Converting a flat list to a list of tuples

bonono at gmail.com bonono at gmail.com
Wed Nov 23 13:18:03 CET 2005


Bengt Richter wrote:
> >it's not only the order that matters, but also the number of items
> >read from the source iterators on each iteration.
> >
> Not sure I understand.
>
> Are you thinking of something like lines from a file, where there might be
> chunky buffering? ISTM that wouldn't matter if the same next method was called.
> Here we have multiple references to the same iterator. Isn't e.g. buiding
> a plain tuple defined with evaluation one element at a time left to right?
> So an iterator it = xrange(4) can't know that it's being used in a context
> like (it.next(), it.next()), so why should zip be any different? Zip _is_ building
> tuples after all, and it's perfectly clear where they are coming from (or am
> I missing something?) Why not left to right like a normal tuple?
>
The implementor of zip() may select to buffer the iterables so instead
of it.next(), it may loop it for a number of tmes, or emit multiple
threads making it async and all those kind of thing.

However, I would say this is highly unlikely or like a extremely remote
scenario to prove that this usage is wrong and we are bad boys  ;-)




More information about the Python-list mailing list