4 ms·
> Even when programming in python, half the time I find myself switching to a simple loop over an index because I realize I need the index. If you need to iter
by dragonwriter 5y ago
> Even when programming in python, half the time I find myself switching to a simple loop over an index because I realize I need the index.
If you need to iterate over an iterable xs and discover you need the index as well, in Python you shouldn't switch to a loop over the index, you should switch from:
for x in xs:
...
to:
for idx, x in enumerate(xs):
...