PYTHON
python3 iterate through indexes
items=['baseball','basketball','football']
for index, item in enumerate(items):
print(index, item)
python for with iterator index
for index, value in enumerate(iterator):
print(index, value)
for loop with index python3
colors = ["red", "green", "blue", "purple"]
for i in range(len(colors)):
print(colors[i])
python iterate with index
for index, item in enumerate(iterable, start=1):
print index, item
python for loop with index
colors = ["red", "green", "blue", "purple"]
for i in range(len(colors)):
print(colors[i])
python for loop index
# Creates two variables; An index (num), and the value at that index (line)
for num, line in enumerate(lines):
print("{0:03d}: {}".format(num, line))
for loop with index python
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for i in range(len(presidents)):
print("President {}: {}".format(i + 1, presidents[i]))
python loop with index
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for num, name in enumerate(presidents, start=1):
print("President {}: {}".format(num, name))
iterating with index in for loops python
colors = ["red", "green", "blue", "purple"]
ratios = [0.2, 0.3, 0.1, 0.4]
for color, ratio in zip(colors, ratios):
print("{}% {}".format(ratio * 100, color))