import heapq Since the built in heapq library is a minheap, multiply your values by -1 and it will function as a max heap. Just remeber that all your numbers have been inverted.