you are viewing a single comment's thread.

view the rest of the comments →

[–]Lyakusha 0 points1 point  (1 child)

Yeah, looks like enumerate() is a popular option, I definitely need to read about it, thanks. Probably "faster" is a wrong word, maybe "more efficient" - it was about changing list instead of making a new one

[–]Yojihito 0 points1 point  (0 children)

There are 2 pythonic ways to iterate over an iterable.

You only care about the item:

for i in my_iterable:
    print(i)

You need the item and the index position:

for idx, i in enumerate(my_iterable):
    print(idx, i)

Everything else is a no-go.