Python enumerate() built-in function
From the Python 3 documentation
Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. The __next__() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable.
Introduction
The enumerate() function in Python is a built-in function that adds a counter to an iterable. It returns an enumerate object, which yields pairs containing a count (from a starting index, which defaults to 0) and the corresponding value from the iterable. This is particularly useful when you need both the index and the item while looping over a sequence.
Examples
l = enumerate([1, 2, 3, 4, 5])
print(l)
print(l.__next__())
print(l.__next__())
print(l.__next__())
print(l.__next__())
print(l.__next__())
<enumerate object at 0x7fcac409cc40>
(0, 1)
(1, 2)
(2, 3)
(3, 4)
(4, 5)
enumerate is usually used in a for loop to get the index of an item:
for i, item in enumerate([1, 2, 3, 4, 5]):
print(f"Index: {i}, Item: {item}")
Index: 0, Item: 1
Index: 1, Item: 2
Index: 2, Item: 3
Index: 3, Item: 4
Index: 4, Item: 5