Collection Methods
collections.deque.insert()
Insert a value at the given index. Unlike append, insertion into a full bounded deque raises IndexError.
Formal Syntax & Structure
python syntaxpython
deque_instance.insert(i, x, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | int | Index at which to insert. |
| x | object | Value to append, remove, search for or insert. |
Return Value
None
No return value; the operation changes the receiver in place.
Working Example
Example Snippetpython
import collectionsd=collections.deque([1,3])d.insert(1,2)print(list(d))