heapq.heapify()
heapq.heapify() is a Python function in the Heapq Module category. Transforms a list into a heap (min-heap), in-place, O(n) time. The syntax is heapq.heapify(x). Parameters: x — mutable list. Returns: None. A typical example: import heapq
h = [3, 1, 4, 1, 5, 9]
heapq.heapify(h)
# h = [1, 1, 4, 3, 5, 9] (heap property). A close sibling is heapq.heappush(), which pushes an item onto the heap, maintaining the heap invariant. A close sibling is heapq.heappop(), which pops and returns the smallest item from the heap. 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.heappush(), heapq.heappop(), heapq.heappushpop(), heapq.heapreplace(), heapq.nlargest(), heapq.nsmallest().