#!/usr/bin/python
# -*- coding: utf-8 -*-
list1 = [3, 7, 8, 9, 12]
list2 = [5, 6, 10, 13, 25, 30]
result = []

while list1 and list2:
    if list1[0] < list2[0]:
        result.append(list1[0])
        list1.remove(list1[0])
    else:
        result.append(list2[0])
        list2.remove(list2[0])

#list1元素已全部添加到result,此时只需将剩余的元素添加到resultfor i in list2:
    result.append(i)
print(result)
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐