Access the index of a Python for loop (enumerate)


Access the index of a Python for loop

#create list
a = [5,6,17,20]
#here we can use python's built-in enumerate function:
for idx, val in enumerate(a):
    print(idx, val)
0 5

1 6
2 17
3 20


Ace your next data science interview

Get better at data science interviews by solving a few questions per week



Find a bug? Submit a suggested change on Github, or message me on Twitter.