Python deque - Insert an object at the first position

The appendleft() of a deque inserts an object at the first position.

from collections import deque

d = deque([1, 2, 3])
d.appendleft(7)

print(d)  # deque([7, 1, 2, 3])

for i in d:
    print(i)

# 7
# 1
# 2
# 3

Python Deque

Python Tutorial