heapq.heappop()
heapq.heappop() is a Python function in the Heapq Module category. Pops and returns the smallest item from the heap. The syntax is heapq.heappop(heap). Parameters: heap. Returns: Smallest item. A typical example: h = [1, 3, 5, 7]
heapq.heappop(h) # 1
heapq.heappop(h) # 3. A close sibling is heapq.heapify(), which transforms a list into a heap (min-heap), in-place, O(n) time. A close sibling is heapq.heappush(), which pushes an item onto the heap, maintaining the heap invariant. A close sibling is heapq.heappushpop(), which pushes item then pops the smallest. More efficient than heappush then heappop. A close sibling is heapq.heapreplace(), which pops then pushes — more efficient than heappop then heappush. More about this category: Heap queue algorithm — heapify, heappush, heappop, nlargest. Related Heapq Module entries: heapq.heapify(), heapq.heappush(), heapq.heappushpop(), heapq.heapreplace(), heapq.nlargest(), heapq.nsmallest(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.