Answers for "list index python for loop"

17

python access index in for loop

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

#if you want to start from 1 instead of 0
for count, item in enumerate(items, start=1):
    print(count, item)
Posted by: Guest on July-03-2020
7

for loop with index python3

colors = ["red", "green", "blue", "purple"]

for i in range(len(colors)):
    print(colors[i])
Posted by: Guest on January-28-2020
0

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))
Posted by: Guest on August-20-2020

Python Answers by Framework

Browse Popular Code Answers by Language