On this page
heapq.heappop
Prev: heapq.heapify_max | Up: heapq | Next: heapq.heappop_max
Rel: heapq.heapify, heapq.heapify_max, heapq.heappop_max, heapq.heappush
Ref: docs.python.org — heapq.heappop
Tags: #public #python3 #stdlib #heapq
Import
import heapq
from heapq import heappop
Signature & Overview
heapq.heappop(heap, /)
Pop the smallest item off the heap, maintaining the heap invariant.
Usage
import heapq
h = [3, 1, 2]
heapq.heapify(h)
assert [heapq.heappop(h) for _ in range(3)] == [1, 2, 3]
Gotchas
- Raises
IndexErroron an empty heap.
REPL Inspect
from heapq import heappop
help(heappop)
Linked from
- tuts/python3/stdlib_module/heapq
- tuts/python3/stdlib_module/heapq/heapify
- tuts/python3/stdlib_module/heapq/heapify_max
- tuts/python3/stdlib_module/heapq/heappop_max
- tuts/python3/stdlib_module/heapq/heappush
- tuts/python3/stdlib_module/heapq/heappush_max
- tuts/python3/stdlib_module/heapq/heappushpop
- tuts/python3/stdlib_module/heapq/heappushpop_max
- tuts/python3/stdlib_module/heapq/heapreplace
- tuts/python3/stdlib_module/heapq/heapreplace_max
- tuts/python3/stdlib_module/heapq/merge
- tuts/python3/stdlib_module/heapq/nlargest
- tuts/python3/stdlib_module/heapq/nsmallest
Related notes
- tuts/python3/stdlib_module/heapq/heapify Linked here; links to this page; shared tags: #heapq, #stdlib
- tuts/python3/stdlib_module/heapq/heapify_max Linked here; links to this page; shared tags: #heapq, #stdlib
- tuts/python3/stdlib_module/heapq/heappop_max Linked here; links to this page; shared tags: #heapq, #stdlib
- tuts/python3/stdlib_module/heapq/heappush Linked here; links to this page; shared tags: #heapq, #stdlib
- tuts/python3/stdlib_module/heapq Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/heapq/heappush_max links to this page; shared tags: #heapq, #stdlib
- tuts/python3/stdlib_module/heapq/heappushpop links to this page; shared tags: #heapq, #stdlib
- tuts/python3/stdlib_module/heapq/heappushpop_max links to this page; shared tags: #heapq, #stdlib
- tuts/python3/stdlib_module/heapq/heapreplace links to this page; shared tags: #heapq, #stdlib
- tuts/python3/stdlib_module/heapq/heapreplace_max links to this page; shared tags: #heapq, #stdlib