In Python, an iterable may be traversed using a simple for in loop:
|
|
However, what if the current index is desired?
Access the index in a Python for
loop
The recommended pythonic solution is to use the built-in enumerate
function.
|
|
Output:
|
|
For contrast, the unidiomatic way to access the current index is by using range
:
|
|
Output:
|
|