ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
from collections import deque
d = deque([1, 2, 3], maxlen=3)
d.append(4)
d.appendleft(0)
d.rotate(1)
print(list(d), d.maxlen, d[-1])
  1. A. [3, 0, 2] 3 2
  2. B. [2, 3, 0] 3 0
  3. C. [4, 0, 1] 3 1
  4. D. [0, 1, 2] 3 2

Correct answer: A. [3, 0, 2] 3 2

With maxlen=3, append(4) drops 1 from the left: [2, 3, 4]. appendleft(0) drops 4 from the right: [0, 2, 3]. rotate(1) moves the last item to the front: [3, 0, 2], whose last element is 2.

More Python Programming questions

Exams that ask this topic