序列中对应列的值相加 分类: python 小练习 2013-12-05 19:09 293人阅读 评论(0) 收藏
#coding:utf-8
'''
对应列的值相加
'''
a=['8533873.000000', '4922178.500000', '7.419005', '63.000282', '59']
b=['8422450.000000', '4791319.500000', '9.877247', '63.003777', '58']
c=['8617203.000000', '4774758.000000', '12.711574', '63.007469', '59']
def main():
d=[i for i in zip(a,b,c)]
g=lambda m,n:eval(str(m))+eval(str(n))
print d
print [reduce(g,i) for i in d]
#方法二
print [sum([eval(k) for k in i]) for i in d]
if __name__ == '__main__':
main()
'''
结果:
[('8533873.000000', '8422450.000000', '8617203.000000'), ('4922178.500000', '4791319.500000', '4774758.000000'), ('7.419005', '9.877247', '12.711574'), ('63.000282', '63.003777', '63.007469'), ('59', '58', '59')]
[25573526.0, 14488256.0, 30.007826, 189.011528, 176]
[25573526.0, 14488256.0, 30.007826, 189.011528, 176]
'''
版权声明:本文为博主原创文章,未经博主允许不得转载。