heapq.heappushpop()

heapq.heappushpop(heap, item) → value. Push item on the heap, then pop and return the smallest item

from the heap. The combined action runs more efficiently than heappush() followed by a separate call to heappop().