Python将数字列表与其他数字列表相加 [英] Python adding lists of numbers with other lists of numbers
本文介绍了Python将数字列表与其他数字列表相加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Python中,有没有一种简单的方法可以将列表的单个数字添加到其他列表的单个数字?在我的代码中,我需要以类似的方式添加大约10个长列表:
In Python is there a simple way of adding the individual numbers of lists to the individual numbers of other lists? In my code I need to add about 10 long lists in a similar fashion to this:
listOne = [1,5,3,2,7]
listTwo = [6,2,4,8,5]
listThree = [3,2,9,1,1]
因此,我希望结果为:
listSum = [10,9,16,11,13]
预先感谢
推荐答案
>>> lists = (listOne, listTwo, listThree)
>>> [sum(values) for values in zip(*lists)]
[10, 9, 16, 11, 13]
这篇关于Python将数字列表与其他数字列表相加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文