← Quiz: Queues and Deques: all 13 questions
Quiz: Queues and Deques · Question 9 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(0)
print(list(q))
- A.[1, 2, 3, 4, 0]
- B.[0, 2, 3, 4]
- C.[0, 1, 2, 3]
- D.[2, 3, 4, 0]
Answer & explanation
Correct answer: [0, 2, 3, 4]
append adds 4 at the back, popleft removes 1 from the front, and appendleft puts 0 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 →