ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import heapq
h = []
for x in [5, 1, 3]:
    heapq.heappush(h, x)
heapq.heappush(h, 0)
print([heapq.heappop(h) for _ in range(2)], len(h))
  1. A. [1, 3] 2
  2. B. [0, 3] 2
  3. C. [0, 1] 2
  4. D. [0, 1] 3

Correct answer: C. [0, 1] 2

Two pops return the two smallest values, 0 and 1. Four items were pushed and two were removed, so two remain.

More Python Programming questions

Exams that ask this topic