I want to write a function that merges two sorted lists in Python 3.
For example:
>> merge_lists([2, 5, 9], [1, 6, 8, 10])
[1, 2, 5, 6, 8, 9, 10]
My implementation is as follows:
def merge_lists(L1, L2):
Outlist = []
while (L1 and L2):
if (L1[0] <= L2[0]):
item = L1.pop(0)
Outlist.append(item)
else:
item = L2.pop(0)
Outlist.append(item)
Outlist.extend(L1 if L1 else L2)
return Outlist
Can I make it better or more readable?