Skip to main content
Post Closed as "Duplicate" by CommunityBot, Mat, alko, Qantas 94 Heavy, devnull
formatting
Source Link
user180100
user180100

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 ?

Thanks.

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 ?

Thanks.

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 ?

I am trying to write a list rotation function in python. CameI 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) =5len(p) = 5 and U =1U = 1, why should be the result of -1%5 = 4-1 % 5 = 4 ?

Thanks.

I am trying to write a list rotation function in python. 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?

Thanks

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 ?

Thanks.

Source Link
joydip134
  • 307
  • 1
  • 2
  • 9

What should be result for -1%5 in python

I am trying to write a list rotation function in python. 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?

Thanks