Count indexes using "for" in Python

The Solution to Count indexes using "for" in Python is


If you have some given list, and want to iterate over its items and indices, you can use enumerate():

for index, item in enumerate(my_list):
    print index, item

If you only need the indices, you can use range():

for i in range(len(my_list)):
    print i

~ Answered on 2012-03-01 21:14:56


Most Viewed Questions: