With index
animals = ["dog", "cat", "mouse"]
# enumerate() adds counter to an iterable
for i, value in enumerate(animals):
print(i, value)
Prints: 0 dog 1 cat 2 mouse
Comments
animals = ["dog", "cat", "mouse"]
# enumerate() adds counter to an iterable
for i, value in enumerate(animals):
print(i, value)
Prints: 0 dog 1 cat 2 mouse