def heappushpop(heap, item):
 if (heap and (heap[0] < item)):
  (item, heap[0]) = (heap[0], item)
  _siftup(heap, 0)
 return item

def heappushpop ( heap , item ) : if ( heap and ( heap [ 0 ] < item ) ) : ( item , heap [ 0 ] ) = ( heap [ 0 ] , item ) _siftup ( heap , 0 ) return item
fast version of a heappush followed by a heappop .