整体的思路就是我们比较第一位数字,比较后,就将小的那个添加到空列表中,然后再把列表中的这个数字删除掉,当其中一个列表变为空时,就将另外一个列表跟list3合并。
def get_ret(list1, list2):
list3 = []
while len(list1) > 0 and len(list2) > 0:
if list1[0] < list2[0]:
(list1[0])
del list1[0]
else:
(list2[0])
del list2[0]
(list1)
(list2)
return list3
ret = get_ret([1, 2, 3], [3, 4, 5])
print(ret)
除了复杂的方法,有比较简单的做法,使用python的内置函数,如下所示:
list3 = list1 + list2
list3 = ()