Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python loop with int iterator [duplicate]

Tags:

python

loops

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?

like image 914
Smashery Avatar asked Dec 13 '22 09:12

Smashery


1 Answers

for i, value in enumerate(values):
like image 141
Amber Avatar answered Dec 14 '22 22:12

Amber