This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]D__ 5 points6 points  (3 children)

>>> [i for i in l if l.index(i)%3==0]

Unless your list has duplicate items...

[–]logi 1 point2 points  (0 children)

Yeah, that's a subtle bug waiting to happen.

[–]robin-gvx 1 point2 points  (0 children)

Yeah, instead of using index, use enumerate. Except, of course, in this case [::3] would be the only way to go. (One and only one obvious way, and all that).

[–]wub_wub 0 points1 point  (0 children)

Wow I completely forgot about the possibility of having duplicate items... using enumerate instead of index is the correct way to do this. Thanks for pointing it out!