Question 7
Back to Exercise
What is the output of the following Python program?
from collections import deque
recent = deque([1, 2, 3], maxlen=3)
recent.append(4)
recent.appendleft(0)
print(recent, len(recent))
- A deque([2, 3, 4], maxlen=3) 3
- B deque([0, 2, 3], maxlen=3) 3 Correct
- C deque([0, 1, 2, 3, 4]) 5
- D deque([0, 3, 4], maxlen=3) 3
Correct Answer: Option B
append(4) pushes 1 out of the left end: [2, 3, 4]. appendleft(0) then pushes 4 out of the right end: [0, 2, 3].
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!