Heap Functions

heapq.heappop()

Remove and return the smallest heap item, preserving the invariant. An empty heap raises IndexError.

Formal Syntax & Structure

python syntaxpython
heapq.heappop(heap, /)

Parameters & Attributes

NameTypeDescription
heaplistMutable list satisfying the min-heap invariant unless heapifying.

Return Value

object

The object result described above.

Working Example

Example Snippetpython
import heapqheap=[1,3,2]print((heapq.heappop(heap),sorted(heap)))
Python Reference