How to rotate deque right and left in Python

1 Answer

0 votes
import collections     

d = collections.deque(range(10)) 
print(d) 

d.rotate(3)
print(d) 

d.rotate(-4)
print(d) 




'''
run:

deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
deque([7, 8, 9, 0, 1, 2, 3, 4, 5, 6])
deque([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])

'''

 



answered May 7, 2019 by avibootz

Related questions

1 answer 152 views
152 views asked Jul 21, 2020 by avibootz
1 answer 170 views
170 views asked Jul 21, 2020 by avibootz
1 answer 179 views
1 answer 111 views
111 views asked Nov 16, 2022 by avibootz
1 answer 195 views
...