max(d.values())
will give you the maximum value (100), but to remove an entry from the dictionary you will need the appropriate key ( 'A'
).
You can do it:
d = {'A':100, 'a':10, 'T':50, 't':5} key_to_delete = max(d, key=lambda k: d[k]) del d[key_to_delete]
By the way, you should not call the dictionary dict
, because it is a name of a built-in type.
If there can be several records with the same maximum value, and you want to delete all of them:
val_to_delete = max(d.values()) keys_to_delete = [k for k,v in d.iteritems() if v==val_to_delete] for k in keys_to_delete: del d[k]
source share