python - How do you find which value occurs the most in a dictionary? -


in dictionary keys , list of values, how find value in lists of values frequently? i'm assuming use loops , append lists unsure of how so. want print value occurring frequently?

thank you!

please keep in mind i'm new programming , not familiar lambda or other complicated ways solve this.

one way use collections.counter

from collections import counter  >>> d = {'a': 5, 'b': 3, 'c': 5, 'd': 1, 'e': 5} >>> c = counter(d.values()) >>> c [(5, 3), (1, 1), (3, 1)]  >>> c.most_common()[0] (5, 3)   # value, , number of appearances 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -