Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to track indexes in python?

Right now I am tracking my index in side the loop like this

index = 0
for entry in longList:
    if entry == 'foo':
        print index
    index += 1

is there a better way to do this?

like image 772
John Avatar asked Aug 29 '11 17:08

John


1 Answers

for index, entry in enumerate(longList):
    if entry == 'foo':
        print index
like image 52
Bill Lynch Avatar answered Oct 02 '22 16:10

Bill Lynch