如何按字典中的值对字典列表进行排序?

use*_*413 7 python sorting dictionary list

可能重复:
在Python中如何按字典值对字典列表进行排序?

我正在编写一个Python 3.2应用程序,我有一个包含以下内容的词典列表:

teamlist = [{ "name":"Bears", "wins":10, "losses":3, "rating":75.00 },
            { "name":"Chargers", "wins":4, "losses":8, "rating":46.55 },
            { "name":"Dolphins", "wins":3, "losses":9, "rating":41.75 },
            { "name":"Patriots", "wins":9, "losses":3, "rating": 71.48 }]
Run Code Online (Sandbox Code Playgroud)

我希望列表按评级键中的值排序.我该如何做到这一点?

eca*_*mur 6

使用operator.itemgetter的关键:

sorted(teamlist, key=operator.itemgetter('rating'))
Run Code Online (Sandbox Code Playgroud)