Open this example in the interactive library
Source code
import heapq
values = [7, 2, 9, 1]
heapq.heapify(values)
print(heapq.heappop(values))Sample output
1

Read the smallest heap item. A self-contained example using the Python standard library.
Open this example in the interactive library
import heapq
values = [7, 2, 9, 1]
heapq.heapify(values)
print(heapq.heappop(values))1