回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我搞不清函数之间的区别(除了push/pop操作的有序性)heapq.heappushpop()和heapq.heapplace公司()当我测试以下代码时。在</p>
<pre><code>>>> from heapq import *
>>> a=[2,7,4,0,8,12,14,13,10,3,4]
>>> heapify(a)
>>> heappush(a,9)
>>> a
[0, 2, 4, 7, 3, 9, 14, 13, 10, 8, 4, 12]
>>> heappop(a)
0
>>> b=a.copy()
>>> heappushpop(a,6)
2
>>> heapreplace(b,6)
2
>>> a
[3, 4, 4, 7, 6, 9, 14, 13, 10, 8, 12]
>>> b
[3, 4, 4, 7, 6, 9, 14, 13, 10, 8, 12]
</code></pre>