我有以下两个列表:
first = [1,2,3,4,5]
second = [6,7,8,9,10]
现在我想将这两个列表中的项目添加到一个新列表中。
输出应该是
third = [7,9,11,13,15]
first = [1,2,3,4,5]
second = [6,7,8,9,10]
third=[]
for i,j in zip(first,second):
t=i+j
third.append(t)
print("Third List=",third)
output -- Third List= [7, 9, 11, 13, 15]
你可以使用这种方法,但前提是两个列表的大小必须相同:
first = [1, 2, 3, 4, 5]
second = [6, 7, 8, 9, 10]
third = []
a = len(first)
b = int(0)
while True:
x = first[b]
y = second[b]
ans = x + y
third.append(ans)
b = b + 1
if b == a:
break
print third