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 170 views
170 views asked Jul 21, 2020 by avibootz
1 answer 152 views
152 views asked Jul 21, 2020 by avibootz
1 answer 164 views
2 answers 172 views
1 answer 262 views
262 views asked Jul 21, 2020 by avibootz
...