Advertisement
here2share

# list_rotation.py

Jul 24th, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. # list_rotation.py
  2.  
  3. def list_rotation(lst,n):
  4.     n = n%len(lst)
  5.     return lst[n:]+lst[:n]
  6.  
  7. print (list_rotation([1,6,9,0,8,-4,7,6],3)) # result=[0, 8, -4, 7, 6, 1, 6, 9]
  8. print (list_rotation([1,6,9,0,8,-4,7,6],-2)) # result=[7, 6, 1, 6, 9, 0, 8, -4]
  9. print (list_rotation([1,6,9,0,8,-4,7,6],12)) # result=[8, -4, 7, 6, 1, 6, 9, 0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement