heapq.heapify(x)
python">import heapq
my_list = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
heapq.heapify(my_list)
print(my_list)
heapq.heappush(heap, item)
python">import heapq
my_heap = []
heapq.heappush(my_heap, 3)
heapq.heappush(my_heap, 1)
heapq.heappush(my_heap, 4)
print(my_heap)
heapq.heappop(heap)
python">import heapq
my_heap = [1, 3, 4]
min_item = heapq.heappop(my_heap)
print(min_item)
print(my_heap)
heapq.heapreplace(heap, item)
python">import heapq
my_heap = [1, 3, 4]
new_item = 0
replaced_item = heapq.heapreplace(my_heap, new_item)
print(replaced_item)
print(my_heap)
heapq.nlargest(n, iterable, key=None)
python">import heapq
my_list = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
largest_3 = heapq.nlargest(3, my_list)
print(largest_3)students = [{'name': 'Alice', 'score': 85},{'name': 'Bob', 'score': 92},{'name': 'Charlie', 'score': 78},{'name': 'David', 'score': 90}
]
top_two_students = heapq.nlargest(2, students, key=lambda s: s['score'])
print(top_two_students)
heapq.nsmallest(n, iterable, key=None)
python">import heapq
my_list = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
smallest_3 = heapq.nsmallest(3, my_list)
print(smallest_3)
nums = [4, 2, 7, 1]
result = heapq.nsmallest(2, nums)
print(result)