In brief
heapq maintains a min-heap with the smallest item at the front. heappush() adds a value and heappop() retrieves the smallest while preserving the structure.
Useful to know
heapq maintains a min-heap with the smallest item at the front. heappush() adds a value and heappop() retrieves the smallest while preserving the structure. [1]
This suits a queue of upcoming tasks with numeric priorities. The remaining list is not necessarily fully sorted. Do not display it as a finished ranking without further processing, and define how equal priorities should be handled.
Sources
For further detail and to check the information: