Built-ins & Standard Library · Question 10 · Medium

A deque gets an appendleft, a pop and a rotate(1). What does it hold at the end?

from collections import deque

q = deque([1, 2, 3])
q.appendleft(0)
q.pop()
q.rotate(1)
print(list(q))
  1. [1, 2, 0]
  2. [0, 1, 2]
  3. [1, 2, 3]
  4. [2, 0, 1]
Answer and explanation

Answer: D. [2, 0, 1]

Explanation: appendleft(0) gives 0, 1, 2, 3. pop() removes from the right end, leaving 0, 1, 2. rotate(1) moves one item from the right end to the front, giving 2, 0, 1.

Previous: Words are grouped by their first letter using defaultdict(list). What does the… · Next: max is called on a dictionary of city temperatures, once plainly and once with…

Practise built-ins & standard library

Try a fresh set of built-ins & standard library questions with an explanation after every answer, free and without signing up: Built-ins & Standard Library practice. Or sit a full placement mock test.

More built-ins & standard library questions

More python practice

Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge