Heap Functions
heapq.merge()
Lazily merge inputs that are already sorted in the chosen direction. It does not sort unsorted inputs; reverse=True requires descending inputs.
Formal Syntax & Structure
python syntaxpython
heapq.merge(*iterables, key=None, reverse=False)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| iterables | iterable | Zero or more input iterables. |
| key | callable or None | Optional key function used for comparison or grouping. |
| reverse | bool | Use descending order when true. |
Return Value
iterator
The iterator result described above.
Working Example
Example Snippetpython
import heapqprint(list(heapq.merge([1,4],[2,3])))