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 151 views
151 views asked Jul 21, 2020 by avibootz
1 answer 169 views
169 views asked Jul 21, 2020 by avibootz
1 answer 179 views
1 answer 110 views
110 views asked Nov 16, 2022 by avibootz
1 answer 195 views
...