ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from collections import deque
d = deque([1, 2, 3])
d.extendleft([4, 5])
print(list(d))
  1. A. [3, 2, 1, 4, 5]
  2. B. [5, 4, 1, 2, 3]
  3. C. [4, 5, 1, 2, 3]
  4. D. [1, 2, 3, 4, 5]

Correct answer: B. [5, 4, 1, 2, 3]

extendleft adds each item to the left end in turn, so 4 goes in front of 1 and then 5 goes in front of 4. The items arrive in reversed order.

More Python Programming questions

Exams that ask this topic