So I want to move all the elements to the right so for example if I had a list of [1, 2, 3, 4, 5]
it would become [5, 1, 2, 3, 4]
. So basically the rightmost element wraps around to the leftmost element and the other elements basically shift the right.
Here is my code:
length = len(values)
old_right = values[length - 1]
for j in range(length - 1, 0, -1):
values[j] = values[j - 1]
values[0] = old_right
When i enter it in idle i get an error on the last line on values[0] (highlighted on values) saying SyntaxError: invalid syntax
. I do not know why I get this error.
Also, how would I have to change my code to make it go from [5, 4, 3, 2, 1]
back to [1, 2, 3, 4, 5]
, i.e. reverse the process?