For example, if the given dictionary is as following:
dic = {('K1', 'S1'): 4.999997655759467,
('k1', 'K2'): 6.1999036349232375,
('K1', 'K4'): 7.999999999999876,
('K2', 'K1'): 6.199940422452897,
('K2', 'K3'): 7.999999999999876,
('K2', 'K5'): 6.199962763954776,
('K3', 'K2'): 6.199997321675397,
('K3', 'K6'): 7.999998023783301,
('K3', 'S2'): 9.999999999999911,
('K4', 'S1'): 9.999999999999911,
('K4', 'K1'): 6.199999975663285,
('K4', 'K5'): 6.19999999303405,
('K5', 'K2'): 6.199989058277423,
('K5', 'K4'): 7.999999999999876,
('K5', 'K6'): 7.999950953156936,
('K6', 'S2'): 9.999999999999911,
('K6', 'K3'): 7.999641214892367,
('K6', 'K5'): 6.19980050493078}
And the required output is as follows:
{('K1', 'K4'): 7.999999999999876,
('K2', 'K3'): 7.999999999999876,
('K3', 'S2'): 9.999999999999911,
('K4', 'S1'): 9.999999999999911,
('K5', 'K4'): 7.999999999999876,
('K6', 'S2'): 9.999999999999911}
I implemented the following function, but unfortunately it can only get the value and it doesn't get the corresponding key.
def getMaxForX(number):
return max([v for k, v in dic.items() if k[0] == number])
I don't fully understand the concept of max key and values for a dictionary?
Please suggest how I can fix this.