考虑我有一个列表列表:
[[5, 10, 30, 24, 100], [1, 9, 25, 49, 81]]
[[15, 10, 10, 16, 70], [10, 1, 25, 11, 19]]
[[34, 20, 10, 10, 30], [9, 20, 25, 30, 80]]
Run Code Online (Sandbox Code Playgroud)
现在我想要第一个列表的索引的所有索引的总和,然后是第二个列表 5+15+34=54 10+10+20=40
,依此类推:
[54,40,50, 50,200], [20,30,75,90,180]
Run Code Online (Sandbox Code Playgroud)
我试过了:
for res in results:
print [sum(j) for j in zip(*res)]
Run Code Online (Sandbox Code Playgroud)
这results是列表清单.但它给出了每个列表项的总和:
[6,19,55,73,181]
[25,11,35,27,89]
[43,40,35,40,110]
Run Code Online (Sandbox Code Playgroud)