merge list of sorted lists code example
Example 1: python merge list of lists
flat_list = [item for sublist in t for item in sublist]
Example 2: merge two sorted lists python
from heapq import merge
# initializing lists
test_list1 = [1, 5, 6, 9, 11]
test_list2 = [3, 4, 7, 8, 10]
# printing original lists
print ("The original list 1 is : " + str(test_list1))
print ("The original list 2 is : " + str(test_list2))
# using heapq.merge()
# to combine two sorted lists
res = list(merge(test_list1, test_list2))
# printing result
print ("The combined sorted list is : " + str(res))