Setup
dict_of_dicts = {
'test1': {'Ashwin' :84, 'Kohli': 120},
'test2': {'ashwin': 59, 'Pujara': 42},
'test3': {'Pandas': 120, 'R': 119}
}
Solution
It appears that you have a dict of dicts (not a list). You need to iterate through each value in the list and see if it is higher that the max value (initially set to None, along with the name of the player and the first key, e.g. test1
, test2
, etc.). If it is, reset their values to the new max value and append the player name and key to the list holding those who obtained the max value (to account for ties, e.g. Kohli & Pandas).
def orangecap(dict_of_dicts):
max_key_name = []
max_score = None
for key in dict_of_dicts:
for name, score in dict_of_dicts[key].iteritems(): # .items() in Python 3.
if score > max_score:
max_key_name = [(key, name)]
max_score = score
elif score == max_score:
max_key_name.append((key, name))
return max_key_name, max_score
>>> orangecap(dict_of_dicts=dict_of_dicts)
([('test1', 'Kohli'), ('test3', 'Pandas')], 120)