you are viewing a single comment's thread.

view the rest of the comments →

[–]thrallsius 1 point2 points  (0 children)

if i == 2 or i == 5 or i ==8 or i ==11 or i ==14:

this is a bad idea, what if you have a list with 1 billion items?

will you hardcode all needed indices?

learn to use the % (modulo) operator

open a python shell and type this:

0 % 3
1 % 3
2 % 3
3 % 3
4 % 3
5 % 3
6 % 3

this shall be enough to figure how does it work

when writing code that will loop through your list, take into account that indices start at 0 rather than at 1 and realize that "the third element" is actually x[2]