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 157 views
157 views asked Jul 21, 2020 by avibootz
1 answer 178 views
178 views asked Jul 21, 2020 by avibootz
1 answer 184 views
1 answer 114 views
114 views asked Nov 16, 2022 by avibootz
1 answer 197 views
...