Extendleft() method in Python

Method Name:

extendleft

 

Method Signature:

extendleft(iterable)

 

Method Overview:

  • extendleft() adds elements from an iterable to the left side of an already existing deque object.

 

Example:

import collections

 

multiples       = (0, -10, -20)

 

# Create a deque instance from a tuple of two elements

dequeInstance   = collections.deque((10, 20))

print("Initial deque:")

print(dequeInstance)

 

# Extend the deque on the left side using a tuple

print("Deque after exetending it on the left side:")

dequeInstance.extendleft(multiples)

print(dequeInstance)

 

Output:

Initial deque:

deque([10, 20])

Deque after exetending it on the left side:

deque([-20, -10, 0, 10, 20])


Copyright 2024 © pythontic.com