dict in dict sort memo
#Number of team home runs per stadium
homerun_dict = {
    'tokyo_dome': {'home_team': 10, 'hanshin': 8, 'hiroshima': 20},
    'koshien': {'home_team': 20, 'kyojin': 18, 'hiroshima': 12},
    'zoomzoom': {'home_team': 30, 'kyojin': 6, 'hanshin': 30},
}
homerun_dict_sorted = sorted(homerun_dict.items(), key=lambda x:x[1]['home_team'], reverse=True)
print(homerun_dict_sorted)
# [
#   ('zoomzoom', {'home_team': 30, 'kyojin': 6, 'hanshin': 30}),
#   ('koshien', {'home_team': 20, 'kyojin': 18, 'hiroshima': 12}),
#   ('tokyo_dome', {'home_team': 10, 'hiroshima': 20, 'hanshin': 8})
# ]
Recommended Posts