Python extendleft()
Published Oct 21, 2025
Contribute to Docs
The extendleft() method adds multiple elements to the left end of a deque from any iterable (like a list, tuple, or another deque, adding them in reverse order. It modifies the deque in place and returns None.
Syntax
deque.extendleft(iterable)
Parameter:
iterable: A sequence or iterable whose elements will be added to the left end of the deque.
Return value:
This method does not return any value. It modifies the deque in-place.
Note: Elements are added in reverse order of the iterable.
Example
In this example, extendleft() adds elements from a list and another deque to the left end of an existing deque:
from collections import deque# Create a dequedq = deque([1, 2, 3])# Extend using a listdq.extendleft([4, 5, 6])print("After extendleft with list:", dq)# Extend using another dequedq.extendleft(deque([7, 8, 9]))print("After extendleft with another deque:", dq)
This example results in the following output:
After extendleft with list: deque([6, 5, 4, 1, 2, 3])After extendleft with another deque: deque([9, 8, 7, 6, 5, 4, 1, 2, 3])
Codebyte Example: Extending a deque with a list and a tuple
In this example, extendleft() adds elements from a list and a tuple on the left, demonstrating its ability to handle different iterables:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours