Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> from collections import deque
- >>> d=deque([1,2,3,4,5])
- >>> d
- deque([1, 2, 3, 4, 5])
- >>> d.rotate(2)
- >>> d
- deque([4, 5, 1, 2, 3])
- >>> d.rotate(-2)
- >>> d
- deque([1, 2, 3, 4, 5])
- or
- >>> li=[1,2,3,4,5]
- >>> li[2:]+li[:2]
- [3, 4, 5, 1, 2]
- >>> li[-2:]+li[:-2]
- [4, 5, 1, 2, 3]
- A smiple and shorthand syntax for array rotation in python is
- arr = arr[numOfRotations:]+arr[:numOfRotations]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement