← All tips

Python: use enumerate for index + value

pythonpatterns

Avoid manual counters when iterating.

for i, v in enumerate(['a','b']):
    print(i, v)