关闭

序列中对应列的值相加

621人阅读 评论(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]

'''


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:986193次
    • 积分:8948
    • 等级:
    • 排名:第2096名
    • 原创:189篇
    • 转载:202篇
    • 译文:1篇
    • 评论:46条
    文章分类
    最新评论