🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Queues and Deques: all 13 questions

Quiz: Queues and Deques · Question 1 of 13

What does this print? (code)

What does this print?

from collections import deque
q = deque([1, 2, 3])
q.append(4)
q.popleft()
q.appendleft(9)
print(list(q))
  1. A.[1, 2, 3, 4, 9]
  2. B.[9, 2, 3, 4]
  3. C.[9, 1, 2, 3]
  4. D.[2, 3, 4, 9]
Answer & explanation

Correct answer: [9, 2, 3, 4]

append adds 4 at the back, popleft removes 1, appendleft puts 9 at the front.

Can you get the rest right without peeking?

Take the timed Quiz: Queues and Deques quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →