fix(curriculum): rename heap module to heapq and correct heap property outputs (#66113)

This commit is contained in:
lockinginfor2026-arch
2026-02-27 01:56:12 -08:00
committed by GitHub
parent e796c06e59
commit 0640350046
2 changed files with 10 additions and 4 deletions
@@ -98,7 +98,7 @@ The heap property determines the relationship between parent and child nodes. Th
- The value of each parent node is less than or equal to the values of its children.
- The smallest element is at the root.
### Python `heap` module example
### Python `heapq` module example
```py
import heapq
@@ -110,12 +110,15 @@ my_heap = []
heapq.heappush(my_heap, 9)
heapq.heappush(my_heap, 3)
heapq.heappush(my_heap, 5)
print(my_heap) # [3, 9, 5]
# Remove smallest element
print(heapq.heappop(my_heap)) # 3
print(my_heap) # [5, 9]
# Push + Pop in one step
print(heapq.heappushpop(my_heap, 2)) # 2
print(heapq.heappushpop(my_heap, 7)) # 5
print(my_heap) # [7, 9]
# Transform list into heap
nums = [5, 7, 3, 1]
@@ -2823,7 +2823,7 @@ The heap property determines the relationship between parent and child nodes. Th
- The value of each parent node is less than or equal to the values of its children.
- The smallest element is at the root.
### Python `heap` module example
### Python `heapq` module example
```py
import heapq
@@ -2835,12 +2835,15 @@ my_heap = []
heapq.heappush(my_heap, 9)
heapq.heappush(my_heap, 3)
heapq.heappush(my_heap, 5)
print(my_heap) # [3, 9, 5]
# Remove smallest element
print(heapq.heappop(my_heap)) # 3
print(my_heap) # [5, 9]
# Push + Pop in one step
print(heapq.heappushpop(my_heap, 2)) # 2
print(heapq.heappushpop(my_heap, 7)) # 5
print(my_heap) # [7, 9]
# Transform list into heap
nums = [5, 7, 3, 1]