PEP 276 Simple Iterator for ints (fwd)

Huaiyu Zhu huaiyu at
Thu Nov 15 20:27:23 CET 2001

On 14 Nov 2001 16:31:28 -0800, Paul Rubin <phr-n2001d at> wrote:
>Sometimes you want to use the index in the loop.  Maybe the loop syntax
>should be extended somehow to easily let you do that.

def items(x):
   return zip(range(len(x)), x)

for i, x  in items(sequence):

If there were an xzip for iterators, and an int-generator xint, then we
could have

def xitems(x):
   return xzip(xint(), x)

which would work for an iterator x without knowing its length beforehand.


More information about the Python-list mailing list