How to rotate deque in Python

1 Answer

0 votes
from collections import deque
   
dq = deque([1, 18, '27', 2, 'python', 26, 19, 50]) 
 
print(dq) 
 
N = 3
dq.rotate(N) 
print(dq) 

N = -3
dq.rotate(N) 
print(dq) 

N = -1
dq.rotate(N) 
print(dq) 



'''
run:

deque([1, 18, '27', 2, 'python', 26, 19, 50])
deque([26, 19, 50, 1, 18, '27', 2, 'python'])
deque([1, 18, '27', 2, 'python', 26, 19, 50])
deque([18, '27', 2, 'python', 26, 19, 50, 1])

'''

 

 



answered Nov 16, 2022 by avibootz

Related questions

1 answer 178 views
178 views asked Jul 21, 2020 by avibootz
1 answer 157 views
157 views asked Jul 21, 2020 by avibootz
1 answer 167 views
2 answers 175 views
1 answer 264 views
264 views asked Jul 21, 2020 by avibootz
...