V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Zuckonit
V2EX  ›  问与答

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

  •  
  •   Zuckonit · Jul 24, 2014 · 7515 views
    This topic created in 4299 days ago, the information mentioned may be changed or developed.
    dict_a = {'a' : 1, 'b' : 2}
    dict_b = {'a' : 2, 'b' : 3}
    如何得到dict_c = {'a': 3, 'b': 5}
    4 replies    2014-07-24 14:43:21 +08:00
    imn1
        2
    imn1  
       Jul 24, 2014
    class collections.Counter([iterable-or-mapping])
    imn1
        3
    imn1  
       Jul 24, 2014
    呃,求和,反应成计数了
    统计方面的习惯都交给pandas了
    Zuckonit
        4
    Zuckonit  
    OP
       Jul 24, 2014
    @lll9p @imn1 thanks
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2462 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 06:05 · PVG 14:05 · LAX 23:05 · JFK 02:05
    ♥ Do have faith in what you're doing.