Key to maxima of dictionary in python -
i have dictionary, "scores", of integers , want find key(s) of highest value. used code:
key = max(scores, key=scores.get)
however, gives 1 key. how deal ties in highest value? 1 number back. in case of tie? how can keys highest value? help.
you run following, example:
max_value = max(scores.values()) keys = [ (i,v) in scores.iteritems() if v == max_value ]
"keys" hold keys correspond maximum value.
Comments
Post a Comment