How to operate on nested dictionary in python 3.x?

后端 未结 5 696
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 14:47

I am stuck with this question, can you solve the challenge? Here we go!

We represent scores of players across a sequence of matches in a two level dictionary as follows:

5条回答
  •  一向
    一向 (楼主)
    2021-01-29 15:05

    Some code golfing with functools.reduce:

    from functools import reduce
    from collections import Counter
    
    v = reduce(lambda x, y: x.update(y) or x, d.values(), Counter()).most_common(1)[0])
    print(v)
    # ('player3', 100)
    

提交回复
热议问题