getting n items at a time from a generator

Igor V. Rafienko igorr at ifi.uio.no
Sat Dec 29 14:36:31 EST 2007


[ Terry Jones ]

[ ... ]

> Also consider this solution from O'Reilly's Python Cookbook (2nd Ed.) p705
> 
>     def chop(iterable, length=2):
>         return izip(*(iter(iterable),) * length)


Is this *always* guaranteed by the language to work? Should the
iterator returned by izip() change the implementation and evaluate the
underlying iterators in, say, reverse order, the solution would no
longer function, would it? Or is it something the return value of
izip() would never do?

(I am just trying to understand the solution, not criticize it. Took a
while to parse the argument(s) to izip in the example).





ivr
-- 
<+Kaptein-Dah> igorr: for få parenteser
<+Kaptein-Dah> igorr: parenteser virker som lubrication under iterasjon
<+Kaptein-Dah> igorr: velkjent



More information about the Python-list mailing list