排序好的list再排序合并
merge([1, 3, 5], [2, 4, 6])
[1, 2, 3, 4, 5, 6]
def merge(lst1, lst2):
list=[]
if lst1==[]:
return lst2
if lst2==[]:
return lst1
while lst1!=[] and lst2!=[]:
if lst1[0]<=lst2[0]:
list.append(lst1[0])
if len(lst1)==1:
list.extend(lst2)
break
lst1=lst1[1:]
if lst1[0]>lst2[0]:
list.append(lst2[0])
if len(lst2)==1:
list.extend(lst1)
break
lst2=lst2[1:]
return list