Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python deque code

Practice adding and removing items at either end, bounded history, and rotation.

Intermediate ~8 min read

Challenge 1

Put the urgent job at the left end before the existing jobs.

python Your answer
from collections import deque

jobs = deque(["compile", "test"])

print(list(jobs))

Press Ctrl⌘Enter to check your answer

Challenge 2

Remove and store the oldest job from the left side of the queue.

python Your answer
from collections import deque

waiting = deque(["A", "B", "C"])
served = 
print(served)
print(list(waiting))

Press Ctrl⌘Enter to check your answer

Challenge 3

Add the new event so the deque keeps only the last three entries.

python Your answer
from collections import deque

recent = deque(["open", "edit", "save"], maxlen=3)

print(list(recent))

Press Ctrl⌘Enter to check your answer

Challenge 4

Move the first player to the end by rotating the deque one step to the left.

python Your answer
from collections import deque

players = deque(["Ari", "Bo", "Cy"])

print(list(players))

Press Ctrl⌘Enter to check your answer