python enumerate for loop code example
Example 1: python3 iterate through indexes
items=['baseball','basketball','football']
for index, item in enumerate(items):
print(index, item)
Example 2: python for with iterator index
for index, value in enumerate(iterator):
print(index, value)
Example 3: enumerate in python
languages = ['Python', 'C', 'C++', 'C#', 'Java']
i = 0
for language in languages:
print(i, language)
i+=1
for i, language in enumerate(languages):
print(i, language)
Example 4: python gt index in for cycle
my_list = [0,1,2,3,4]
for idx, val in enumerate(my_list):
print('{0}: {1}'.format(idx,val))
Example 5: enumerate python
for index,subj in enumerate(subjects):
print(index,subj)
0 Statistics
1 Artificial intelligence
2 Biology
3 Commerce
4 Science
5 Maths
Example 6: python enumerate for loop
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for num, name in enumerate(presidents, start=1):
print("President {}: {}".format(num, name))