首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
广告
V2EX
›
问与答
python2 里面有没有什么优雅的方法对字典相同的 key 求和
Zuckonit
·
2014-07-24 14:04:21 +08:00
· 6976 次点击
这是一个创建于 3879 天前的主题,其中的信息可能已经有所发展或是发生改变。
dict_a = {'a' : 1, 'b' : 2}
dict_b = {'a' : 2, 'b' : 3}
如何得到dict_c = {'a': 3, 'b': 5}
求和
字典
Python
4 条回复
•
2014-07-24 14:43:21 +08:00
1
lll9p
2014-07-24 14:09:19 +08:00
1
http://stackoverflow.com/questions/3490738/how-to-sum-dict-elements
http://stackoverflow.com/questions/8584504/python-sum-on-keys-for-list-of-dictionaries
2
imn1
2014-07-24 14:16:55 +08:00
class collections.Counter([iterable-or-mapping])
3
imn1
2014-07-24 14:19:18 +08:00
呃,求和,反应成计数了
统计方面的习惯都交给pandas了
4
Zuckonit
OP
2014-07-24 14:43:21 +08:00
@
lll9p
@
imn1
thanks
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
实用小工具
·
1384 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 21ms ·
UTC 17:26
·
PVG 01:26
·
LAX 09:26
·
JFK 12:26
Developed with
CodeLauncher
♥ Do have faith in what you're doing.