ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
from collections import deque
d = deque('abc')
d.rotate(1)
d.appendleft('z')
print(''.join(d), d.pop())
  1. A. zcab a
  2. B. abcz c
  3. C. zbca b
  4. D. zcab b

Correct answer: D. zcab b

rotate(1) moves the last item to the front, so the deque is c, a, b. appendleft puts z in front, and pop removes b from the right.

More Python Programming questions

Exams that ask this topic