Converting a flat list to a list of tuples
Fredrik Lundh
fredrik at pythonware.com
Wed Nov 23 07:23:21 EST 2005
Bengt Richter wrote:
> 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?
yeah, but what says that the iterator has to be called during tuple construction?
while 1:
for each sequence:
# optimize cache behaviour!
grab up to N items from each iterator
M = length of shortest output list
for i in range(M):
build tuple and append
if M != N:
break
</F>
More information about the Python-list
mailing list