Python把两个列表索引相同的值相加
方案一
list1=[1,2,3,4,5] list2=[6,7,8,9,10] list3=[] list3=[i + j for i, j in zip(list1, list2)] print(list3)
方案二
import numpy as np
list1=[1,2,3,4,5]
list2=[6,7,8,9,10]
list4=[] list4=np.sum([list1, list2], axis=0).tolist() print(list4)
方案三
list1=[1,2,3,4,5] list2=[6,7,8,9,10] list5=[] for i in range(len(list1)): list5.append(list1[i] + list2[i]) print(list5)