【发布时间】:2016-06-28 02:15:19
【问题描述】:
我想减去两个列表中的值。
a = [1,2,3,4]
b = [1,0,1,5]
c = a - b
#c should be = [0,2,2,-1]
How can I add the corresponding elements of several lists of numbers? 的答案是类似的,但上面的很多答案只适用于添加。
如果可能,请回答如何减去。
【问题讨论】:
-
你的意思是
list,sets 在 Python 中是无序的。 -
How can I add the corresponding elements of several lists of numbers? 的可能重复项。它不完全一样,但它足够接近,可以作为骗子关闭。
-
如果你的大部分代码都是这样的,你应该试试R。用
a和b作为向量,c <- a-b已经可以做你想做的事了。
标签: python python-3.x