heapq – heap queue algorithm
This module implements the min heap queue algorithm.
A heap queue is essentially a list that has its elements stored in such a way that the first item of the list is always the smallest. Insertion and removal of the minimum value are O(log n) operations, making heaps a convenient priority-queue implementation built on a plain list.