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