How to create an ordered list from two other ordered lists [duplicate]

Python has a module in the standard library called heapq. It deals with sorted priority queues and min/max heaps.

heapq.merge allows you to effectively merge multiple sorted inputs:

>>> import operator, heapq
>>> list1 = [[40, 1980], [50, 1970], [70, 1980], [90, 1975]]
>>> list2 = [[60, 1980],[65,1985]]
>>> list(heapq.merge(list1, list2, key=operator.itemgetter(0))
[[40, 1980], [50, 1970], [60, 1980], [65, 1985], [70, 1980], [90, 1975]]