PEP 276 Simple Iterator for ints (fwd)
Huaiyu Zhu
huaiyu at gauss.almadan.ibm.com
Thu Nov 15 14:27:23 EST 2001
On 14 Nov 2001 16:31:28 -0800, Paul Rubin <phr-n2001d at nightsong.com> 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.
Huaiyu
More information about the Python-list
mailing list