code: def heappop_max(heap):
      
      lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
      if heap:
          returnitem = heap[0]
          heap[0] = lastelt
          _siftup_max(heap, 0)
          return returnitem
      return lastelt
docs: Maxheap version of a heappop.