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

heapq.heapify

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


Import

import heapq
from heapq import heapify

Signature & Overview

heapq.heapify(heap, /)

Transform list into a heap, in-place, in O(len(heap)) time.

Usage

import heapq

nums = [5, 1, 8, 3]
heapq.heapify(nums)
assert nums[0] == 1   # min-heap invariant: smallest element at index 0

Gotchas

REPL Inspect

from heapq import heapify
help(heapify)

Linked from

Related notes