Challenge 1
Rearrange the list in place into a valid min-heap.
import heapq
values = [8, 3, 6, 1, 5]
print(values[0])
Press Ctrl⌘Enter to check your answer
Practice building a heap, adding priorities, removing the smallest item, and using a sequence tie-breaker.
Challenge 1
import heapq
values = [8, 3, 6, 1, 5]
print(values[0])
Press Ctrl⌘Enter to check your answer
Challenge 2
import heapq
heap = [2, 5, 8]
print(heapq.heappop(heap))
Press Ctrl⌘Enter to check your answer
Challenge 3
import heapq
heap = [1, 4, 7]
next_priority =
print(next_priority)
print(heap)
Press Ctrl⌘Enter to check your answer
Challenge 4
import heapq
from itertools import count
pending = [(1, 0, "compile")]
sequence = count(1)
print(heapq.heappop(pending)[2])
Press Ctrl⌘Enter to check your answer