getting n items at a time from a generator

Raymond Hettinger python at rcn.com
Sat Dec 29 15:09:01 EST 2007


> >     def chop(iterable, length=2):
> >         return izip(*(iter(iterable),) * length)
>
> Is this *always* guaranteed by the language to work?

Yes!

Users requested this guarantee, and I agreed.  The docs now explicitly
guarantee this behavior.


Raymond



More information about the Python-list mailing list