Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. >>> from collections import deque
  2. >>> d=deque([1,2,3,4,5])
  3. >>> d
  4. deque([1, 2, 3, 4, 5])
  5. >>> d.rotate(2)
  6. >>> d
  7. deque([4, 5, 1, 2, 3])
  8. >>> d.rotate(-2)
  9. >>> d
  10. deque([1, 2, 3, 4, 5])
  11.  
  12.  
  13. or
  14.  
  15. >>> li=[1,2,3,4,5]
  16. >>> li[2:]+li[:2]
  17. [3, 4, 5, 1, 2]
  18. >>> li[-2:]+li[:-2]
  19. [4, 5, 1, 2, 3]
  20.  
  21. A smiple and shorthand syntax for array rotation in python is
  22.  
  23. arr = arr[numOfRotations:]+arr[:numOfRotations]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement