标签:pop EAP 内置模块 模块 heapq imp app 生成 []
In [1]: import heapqIn [2]: h = []
In [3]: h.append(1)
In [4]: h.append(2)
In [5]: h.append(3)
In [6]: h.append(8)
In [7]: h.append(5)
In [8]: h.append(0)
#用heapq 生成一个最小堆
In [9]: heapq.heapify(h)
In [10]: heapq.heappop()
In [11]: heapq.heappop(h)
Out[11]: 0
In [12]: heapq.heappop(h)
Out[12]: 1
In [13]: heapq.heappop(h)
Out[13]: 2
In [14]: heapq.heappop(h)
Out[14]: 3
In [15]: heapq.heappop(h)
Out[15]: 5
In [16]: heapq.heappop(h)
Out[16]: 8
标签:pop EAP 内置模块 模块 heapq imp app 生成 []
原文地址:https://blog.51cto.com/12080420/2389385