← Quiz: Sorting, heapq and bisect: all 10 questions
Quiz: Sorting, heapq and bisect · Question 5 of 10
What does this print? (code)
What does this print?
import heapq
h = []
for x in [5, 1, 4, 2]:
heapq.heappush(h, x)
print(heapq.heappop(h), heapq.heappop(h))
- A.5 1
- B.5 4
- C.1 4
- D.1 2
Answer & explanation
Correct answer: 1 2
heappop always removes the current smallest item.
Can you get the rest right without peeking?
Take the timed Quiz: Sorting, heapq and bisect quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →