# python 列表汇总

Select
• 42

[1, 1, Decimal('1000.00'), 3, 3, Decimal('3000.00'), 0, 0, 0, 7, 7, Decimal('6200.00'), 11, 11, Decimal('10200.00')]
[28, 29, Decimal('25300.00'), 30, 30, Decimal('29500.00'), 0, 0, 0, 99, 100, Decimal('94600.00'), 157, 159, Decimal('149400.00')]
[3, 3, Decimal('2500.00'), 8, 8, Decimal('8000.00'), 0, 0, 0, 17, 17, Decimal('16500.00'), 28, 28, Decimal('27000.00')]

2 个回答

``````from decimal import *
a=[1, 1, Decimal('1000.00'), 3, 3, Decimal('3000.00'), 0, 0, 0, 7, 7, Decimal('6200.00'), 11, 11, Decimal('10200.00')]
b=[28, 29, Decimal('25300.00'), 30, 30, Decimal('29500.00'), 0, 0, 0, 99, 100, Decimal('94600.00'), 157, 159, Decimal('149400.00')]
c=[3, 3, Decimal('2500.00'), 8, 8, Decimal('8000.00'), 0, 0, 0, 17, 17, Decimal('16500.00'), 28, 28, Decimal('27000.00')]
d=[]
for i in range(len(a)):
d.append(a[i]+b[i]+c[i])

print d
``````

`zip` 是干“对应索引位组合”这事的。

``````# -*- coding: utf-8 -*-

from decimal import Decimal

a = [1, 1, Decimal('1000.00'), 3, 3, Decimal('3000.00'), 0, 0, 0, 7, 7, Decimal('6200.00'), 11, 11, Decimal('10200.00')]
b = [28, 29, Decimal('25300.00'), 30, 30, Decimal('29500.00'), 0, 0, 0, 99, 100, Decimal('94600.00'), 157, 159, Decimal('149400.00')]
c = [3, 3, Decimal('2500.00'), 8, 8, Decimal('8000.00'), 0, 0, 0, 17, 17, Decimal('16500.00'), 28, 28, Decimal('27000.00')]

print [sum(x) for x in zip(a, b, c)]``````

###### 你尚未登录，登录后可以
• 和开发者交流问题的细节
• 关注并接收问题和回答的更新提醒
• 参与内容的编辑和改进，让解决方法与时俱进