Python extendleft()

SrikartikMateti's avatar
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.

  • 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

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 deque
dq = deque([1, 2, 3])
# Extend using a list
dq.extendleft([4, 5, 6])
print("After extendleft with list:", dq)
# Extend using another deque
dq.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:

Code
Output
Loading...

All contributors

Contribute to 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