I am trying to write a list rotation function in python. I came across with the the following code :
def move(p, U):
q = []
for i in range(0,len(p)):
q.append(p[(i-U)%len(p)])
return q
This works perfect. But I am trying to figure out when len(p) = 5
and U = 1
, why should be the result of -1 % 5 = 4
?