How to insert an element at specific index of a deque in Python

1 Answer

0 votes
import collections 
  
q = collections.deque([1, 18, '27', 2, 'python', 18, 19, 18]) 

print(q) 

q.insert(2, 3) 

print(q) 



   
'''
run:
    
deque([1, 18, '27', 2, 'python', 18, 19, 18])
deque([1, 18, 3, '27', 2, 'python', 18, 19, 18])
 
'''

 



answered Jul 21, 2020 by avibootz

Related questions

...