A lazy merge can yield the next smallest item across sorted inputs. Its ordering guarantee depends on each input already being sorted.
Worked example
from heapq import merge
print(list(merge([1, 4, 7], [2, 3, 9])))Result
[1, 2, 3, 4, 7, 9]Implementation notes
The source sequences must use the same comparison key. Merging by timestamp after sorting one feed by name can quietly produce an incorrectly ordered timeline.
Try it yourself
Compare two ordered feeds and deliberately scramble one feed.
Open the Python example →Editorial date July 4, 2025 · Published December 6, 2026