enumerate()
Gives both the index and the element in a loop.
Syntax
for i, element in enumerate(arr):
Description
Returns the sequence number (starting from 0) along with each element. Ideal when you need 'which element it is'.
Example
Loading editor…
Expected output
0 red 1 purple
When to use?
Printing a numbered list, processing by position.