1items=['baseball','basketball','football']
2for index, item in enumerate(items):
3 print(index, item)
1my_list = [0,1,2,3,4]
2for idx, val in enumerate(my_list):
3 print('{0}: {1}'.format(idx,val))
4#This will print:
5#0: 0
6#1: 1
7#2: 2
8#...
1languages = ['Python', 'C', 'C++', 'C#', 'Java']
2
3#Bad way
4i = 0 #counter variable
5for language in languages:
6 print(i, language)
7 i+=1
8
9#Good Way
10for i, language in enumerate(languages):
11 print(i, language)
12
1>>> values = ["a","b","c"]
2>>> for count, value in enumerate(values):
3... print(count, value)
4...
50 a
61 b
72 c
8
1presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
2for num, name in enumerate(presidents, start=1):
3 print("President {}: {}".format(num, name))
4