I am trying to process batches of a vector
let say, I have this vector
v = [10, 20, 30, 40, 70, 80, 90]
I want to print every three elements, if it reaches the end, it goes back to the beginning and takes the first to element and so on. For example, the output would be something like
10, 20, 30
40, 70, 80
90, 10, 20 <== starts over
30, 40, 70
80, 90, 10 <== starts over
and so on...
I know I can do this creating a function and calculating the start and end index using module, but I was thinking if there is a way just playing with the sintaxis, something like
v[8:10 % 9] #would print v[8], v[0] and v[1]
I know you can do this for a single index v[index % len(v)], but is it possible to do it for a range v[range % len(v)]
?