code: def heapreplace_max(heap, item):
      
      returnitem = heap[0]    # raises appropriate IndexError if heap is empty
      heap[0] = item
      _siftup_max(heap, 0)
      return returnitem
docs: Maxheap version of a heappop followed by a heappush.