Zuckonit
V2EX  ›  问与答

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

  •  
  •   Zuckonit · Jul 24, 2014 · 8003 views
    This topic created in 4500 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
    imn1
    Jul 24, 2014
    2
    class collections.Counter([iterable-or-mapping])
    imn1
    imn1
    Jul 24, 2014
    3
    呃,求和,反应成计数了
    统计方面的习惯都交给pandas了
    Zuckonit
    Zuckonit
    OP
    Jul 24, 2014
    4
    @lll9p @imn1 thanks
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4876 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 03:00 · PVG 11:00 · LAX 19:00 · JFK 22:00
    ♥ Do have faith in what you're doing.