so I have this list,
List: [0, 0, 1, 0, 1];
And I need made a algorithm with a for
to show all the list (list[i]
).
When I am in first array position, I can do list[i-2] and list[i-1]
, with this I can see the elements of the last position and the position before the last position.
Exemple : list[0] = 0; list[i-1] = list[4] = 1; list[i-2] = list[3] = 0;
so I can go to the last position and start from there.
But when I do, list[i+1]
in the last position I got a IndexError: list index out of range from the terminal.
My question is: If I was in the last positions and I want again come to from the first one and keep doing the for loop, to see infinite times all array elements from all positions, How I can do it?
If the size of my array it is 5, and I am in second position(list[1]
) in the loop and want do list[i + 11]
, how can I put this representing this, list[2]
?
I am trying make this on python.