Method signature:
popleft()
Parameters:
None
Return value:
None
Overview:
- The popleft() method removes an element from the left side of the deque and returns the value.
- Invoking popleft() on an empty deque raises an exception of type IndexError.
Example:
import collections
numbersDeque = collections.deque((20,40,60,80)) print("Sequence of Numbers:") print(numbersDeque)
elem = numbersDeque.popleft()
print("popleft removed the number:%d"%(elem))
print("Deque elements after a popleft:") print(numbersDeque) |
Output:
Sequence of Numbers: deque([20, 40, 60, 80]) popleft removed the number:20 Deque elements after a popleft: deque([40, 60, 80]) |