CS > Python > Flashcards
How to use Python’s heap data structure?
heapq implements minheap
from heapq import heapify, heappush, heappopfrom heapq import heappushpop
l = [1,2,3] heapify(l) heappush(l, 4) min = heappop(l) min = heappushpop(l, 10)