title: python, heapq: difference between heappushpop() and heapreplace()
body: <p>I couldn't figure out the difference (other than ordinality of push/pop actions) between functions heapq.heappushpop() and heapq.heapreplace() when i tested out the following code.</p>
  
  <pre><code>&gt;&gt;&gt; from heapq import *
  &gt;&gt;&gt; a=[2,7,4,0,8,12,14,13,10,3,4]
  &gt;&gt;&gt; heapify(a)
  &gt;&gt;&gt; heappush(a,9)
  &gt;&gt;&gt; a
  [0, 2, 4, 7, 3, 9, 14, 13, 10, 8, 4, 12]
  &gt;&gt;&gt; heappop(a)
  0
  &gt;&gt;&gt; b=a.copy()
  &gt;&gt;&gt; heappushpop(a,6)
  2
  &gt;&gt;&gt; heapreplace(b,6)
  2
  &gt;&gt;&gt; a
  [3, 4, 4, 7, 6, 9, 14, 13, 10, 8, 12]
  &gt;&gt;&gt; b
  [3, 4, 4, 7, 6, 9, 14, 13, 10, 8, 12]
  </code></pre>