Python3 iteruj poprzez indeksy
items=['baseball','basketball','football']
for index, item in enumerate(items):
print(index, item)
Breakable Buffalo
items=['baseball','basketball','football']
for index, item in enumerate(items):
print(index, item)
my_list = [0,1,2,3,4]
for idx, val in enumerate(my_list):
print('{0}: {1}'.format(idx,val))
#This will print:
#0: 0
#1: 1
#2: 2
#...
colors = ["red", "green", "blue", "purple"]
for i in range(len(colors)):
print(colors[i])
languages = ["Python", "C", "C++", "C#", "Java"]
counter = 1
for item in languages:
print(counter, item)
counter += 1
for item in enumerate(languages):
print(item[0], item[1])
for num,lang in enumerate(languages):
print(num,lang)
[print(num,lang) for num,lang, in enumerate(languages)]
for key, value in enumerate(["p", "y", "t", "h", "o", "n"]):
print key, value
"""
0 p
1 y
2 t
3 h
4 o
5 n
"""
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for num, name in enumerate(presidents, start=1):
print("President {}: {}".format(num, name))