Zuckonit
V2EX  ›  问与答

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

  •  
  •   Zuckonit · Jul 24, 2014 · 7588 views
    This topic created in 4319 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   ·   3204 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 12:10 · PVG 20:10 · LAX 05:10 · JFK 08:10
    ♥ Do have faith in what you're doing.