
Problem –
You want to access the index when using a for loop in python.
Solution –
To access the index in a For loop in Python, You can use enumerate().
In [1]: lst = [2, 4, 6, 8, 10]
In [2]: for idx, item in enumerate(lst):
...: print(idx, item)
...:
0 2
1 4
2 6
3 8
4 10