Using enumerate() for Counters in Loops in Python


When looping through items and you need a counter, use enumerate() instead of manually managing a counter variable.

Source Code

for index, value in enumerate(["apple", "banana", "cherry"]):
    print(index, value)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments