这是我拥有的代码: 如何根据积分和目标对我的团队进行排序?优先考虑得分。
myteams={"Spain":{"points":12 , "goals":6} , "germany":{"points":20 , "goals":10} }
答案必须像:
{"germany":{"points":20 , "goals":10} ,"Spain":{"points":12 , "goals":6} }
答案 0 :(得分:2)
answer = dict(
sorted(myteams.items(), key=lambda x: (x[1]["points"], x[1]["goals"]), reverse=True)
)