V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Zuckonit
V2EX  ›  问与答

python2 里面有没有什么优雅的方法对字典相同的 key 求和

  •  
  •   Zuckonit · 2014-07-24 14:04:21 +08:00 · 6666 次点击
    这是一个创建于 3556 天前的主题,其中的信息可能已经有所发展或是发生改变。
    dict_a = {'a' : 1, 'b' : 2}
    dict_b = {'a' : 2, 'b' : 3}
    如何得到dict_c = {'a': 3, 'b': 5}
    4 条回复    2014-07-24 14:43:21 +08:00
    imn1
        2
    imn1  
       2014-07-24 14:16:55 +08:00
    class collections.Counter([iterable-or-mapping])
    imn1
        3
    imn1  
       2014-07-24 14:19:18 +08:00
    呃,求和,反应成计数了
    统计方面的习惯都交给pandas了
    Zuckonit
        4
    Zuckonit  
    OP
       2014-07-24 14:43:21 +08:00
    @lll9p @imn1 thanks
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3242 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:27 · PVG 21:27 · LAX 06:27 · JFK 09:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.