a = ["12", "23", 35,"45", 89] b = [11, 34, 75, "54", "78"]

new_list = [] for i in range(len(a)): if isinstance(a[i], int) and isinstance(b[i], int): new_list.append(a[i] + b[i]) elif isinstance(a[i], str) and isinstance(b[i], str): new_list.append(int(a[i] + b[i])) else: new_list.append(str(a[i]) + str(b[i]))

print(new_list) # [23, 57, '3575', '99', '7889']

写一个程序将已知列表:a = 12 23 3545 89b = 11 34 75 54 78中同一索引对应的元素进行处理最后得到一个新列表:23 57 3575 997889

原文地址: https://www.cveoy.top/t/topic/b9hb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录