Use enumerate() to Keep a Running Index
In the last lesson, you saw how you can make your loops more Pythonic by iterating over items from a container directly, but what if you need to keep track of the item index?
In this lesson, you’ll see how you can use
enumerate() to keep track of a running index the Pythonic way.
enumerate() is a generator that returns a running index as well as the actual element or item in the container.
Become a Member to join the conversation.