我试图得到dict键,它的值在所有dict的值中都是max.我找到了两种方法,都不够优雅.
d= {'a':2,'b':5,'c':3} # 1st way print [k for k in d.keys() if d[k] == max(d.values())][0] # 2nd way print Counter(d).most_common(1)[0][0]
有更好的方法吗?
python counter dictionary
counter ×1
dictionary ×1
python ×1