【发布时间】:2014-03-19 01:42:18
【问题描述】:
我有一本字典:
d = {'0.766': [('8.0', '-58.47'), ('192.0', '-83.41')], '0.094': [('26.0', '112.01'), ('46.0', '110.19')], '0.313': [('14.0', '75.52'), ('48.0', '77.07')]}
我想在元组中添加相应的值,所以输出看起来像这样:
key, sum of 1st values in tuple, sum of 2nd values in tuple
0.766, 200.0, -141.88
0.094, 72.0, 222.20
...
有没有简单的方法来做到这一点?到目前为止,我找到了 sum(d.values()),但它并没有完全按照我的意愿去做......
干杯, 凯特
PS。现在我也想知道如何获得输出,例如:
key, sum of 1st values in tuple, DIFFERENCE of 2nd values in tuple
0.766, 200.0, 24.94
0.094, 72.0, 1.82
...
当我想执行两个不同的操作时...
谢谢!
【问题讨论】:
标签: python dictionary tuples