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