There is a way to find the key that denotes the highest value in a dictionary (in Python) as per this question. I would like to do it a bit differently though.
Imagine we have a dictionary D, say:
D = {'a' : 1 , 'q' : 2, 'b' : 3, 'c': 2}
I would like to find the maximum value of the dictionary by looping over the values of the keys, each time comparing the values of two keys and then 'remember' the key that denotes highest value in a local variable. In the end, I should have found the key and its maximum value in D. In this case, we should have something like this:
compare('a', 'q') --> remember q
compare('q', 'b') --> remember b
compare('b', 'c') --> remember b
The maximum key is now 'b' with value 3.
But how do I compare the values of the keys in the for loop? How can I do something like:
for k,v in D.iteritems() :
if (dictitem) > (dictitem + 1) :
remember = dictitem
else :
remember = dictitem + 1
But now something that actually works?