PyDocs

Nav

Data Types

heappush

heapq

function
  • heappush(heap, item)
Push item onto heap, maintaining the heap invariant.
1 Example
>>> def heapsort(iterable):
...     h = []
...     for value in iterable:
...         heappush(h, value)
...     return [heappop(h) for i in range(len(h))]
...
>>> heapsort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
from the Python docs
See Also
No see-alsos for heapq/heappush
0 Notes
No notes for heappush