On this page
  1. heapq.heappush_max
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

heapq.heappush_max

Prev: heapq.heappush | Up: heapq | Next: heapq.heappushpop
Rel: heapq.heapify, heapq.heapify_max, heapq.heappop, heapq.heappop_max
Ref: docs.python.org — heapq.heappush_max
Tags: #public #python3 #stdlib #heapq


Import

import heapq
from heapq import heappush_max

Signature & Overview

heapq.heappush_max(heap, item, /)

Push item onto max heap, maintaining the heap invariant.

Usage

import heapq

# Python 3.14+: pushes onto a max-heap
if hasattr(heapq, "heappush_max"):
    h = []
    heapq.heappush_max(h, 2); heapq.heappush_max(h, 9)
    assert h[0] == 9

Gotchas

REPL Inspect

from heapq import heappush_max
help(heappush_max)

Linked from

Related notes