heapq中常用方法如下:
from heapq import *
heapify(heap)#将heap这个列表转为堆,无需返回值
heappush(heap, item)#将 item加入堆heap。
heappop(heap)#将堆中最小元素弹出。
item=heap[0]#查看堆中最小元素
heapreplace(heap, x)#将堆中最小元素弹出,并将元素x 入堆。
merge(*iterables, key=None, reverse=False)#将多个有序的堆合并成一个大的有序堆,然后再输出。
heappushpop(heap, item)#将item 入堆,然后弹出并返回堆中最小的元素。
nlargest(n, iterable, key=None)#返回堆中最大的 n 个元素。
nsmallest(n, iterable, key=None)#返回堆中最小的 n 个元素。