ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import heapq
h = [4, 1, 3]
heapq.heapify(h)
print(h[0], sorted(h))
  1. A. 1 [1, 3, 4]
  2. B. 4 [1, 3, 4]
  3. C. 1 [4, 3, 1]
  4. D. 3 [1, 3, 4]

Correct answer: A. 1 [1, 3, 4]

heapify puts the minimum at index 0. The list order is a heap, not a sorted list, but sorted(h) still shows all three values in ascending order.

More Python Programming questions

Exams that ask this topic