Ordered merge of iterables in Python

Just found out about this cool feature in the Python standard library that allows you to merge two iterables based on a comparison: from heapq import merge as merge_heapwise some_numbers = (1, 5, 10, 15) other_numbers = (2, 4, 6, 8, 10, 12, 14, 16) merged_numbers = tuple(merge_heapwise(some_numbers, other_numbers)) # Using a tuple so comparisons work, for didactic demo reasons assert merged_numbers == (1, 2, 4, 5, 6, 8, …