Iterating by both element and index?...

kenneth.m.mcdonald at sbcglobal.net kenneth.m.mcdonald at sbcglobal.net
Tue Sep 26 00:35:19 EDT 2006


I'd like to iterate over a sequence by both element
and index, something like

for (element, index) in somefun(sequence):
    ...

Obviously this is easy enough to code, but I seem
to remember that such a function was added to
standard Python at some point, but I just can't
dig up a reference to it. Anyone know? I hate
writing even small amounts of code to do something
that's already in the library--it's inelegant,
and probably a lot slower too :-)


Thanks,
Ken




More information about the Python-list mailing list