Access the index of a Python for loop (enumerate)

Python

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