Editor

Predict the deque Output

Beginner · Predict the output · from Python collections: Counter, defaultdict, deque, and More

From the lesson: Python collections: Counter, defaultdict, deque, and More

Imagine you have a basic toolbox with a hammer and a screwdriver. They work fine for simple jobs. But when you're building a deck, you really want a power drill, a level, and a tape measure.

Read the lesson

What does this code print? Think about what appendleft and popleft do, then type the exact output.

from collections import deque
d = deque([1, 2, 3])
d.appendleft(0)
d.append(4)
d.popleft()
print(list(d))
from collections import deque
d = deque([1, 2, 3])
d.appendleft(0)
d.append(4)
d.popleft()
print(list(d))

More collections exercises

All Python exercises · 50 practice problems · Standard Library Essentials quiz