4

Possible Duplicate:
How to get list index and element simultaneously in Python?

I seem to recall there is a built-in way of doing this:

i = 0
for value in values:
    # ...Stuff
    i += 1

but in a neater syntax; something like

for value, i in fn(values):
    # ...Stuff

Is my memory correct; and if so, what is the way of doing this?

Community
  • 1
  • 1
Smashery
  • 54,058
  • 30
  • 96
  • 124

1 Answers1

13
for i, value in enumerate(values):
Amber
  • 477,764
  • 81
  • 611
  • 541