更新时间:2023-08-28 17:16:10
仅仅因为a [i]是元组,您会收到一个错误,您不能直接添加元组.您必须访问它们,实现这一目标的更Python方式是:
You're getting an error just because the a[i] are tuples, you can't add directly tuple. You have to access them, a more pythonic way to achieve this would be:
map(sum, zip(*a))
zip函数可以完全满足您的需求,之后您必须根据需要处理每个条目,在您使用sum
的情况下,您还可以尝试以下操作:
the zip function do exactly what you're looking for, after that you have to process each entry according to what you need, in your case sum
, you can also try this:
result = []
for elem in zip(*a):
result.append(sum(elem))