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

NameTypeDescription
iintIndex at which to insert.
xobjectValue 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))
Python Reference