I recently started to learn Python and my latest assignment is to find element with highest (or lowest) value inside a dictionary which looks like:
Vals = {'a':11, 'b':10, 'c':12, 'a1':12, 'b1':13, 'c1':10, 'd':9}
My code was:
Maxm = 0
for Idx in range (0, len (Vals) - 1):
if Vals [Idx] > Vals [Idx + 1]:
Maxm = Vals [Idx]
elif Vals [Idx] < Vals [Idx + 1]:
Maxm = Vals [Idx + 1]
else:
pass
Then I received a key error. I used something similar to find maximum (minimum) in lists or tuples. I thought it might work with some modification for dictionaries.
NOTE: I can't use Python's built-in functions to find maixmum or minimum. It's unacceptable for us, you know.