🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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))
  1. A.5 1
  2. B.5 4
  3. C.1 4
  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 →