如何根据最大值将字典中的所有值分配给变量

swa*_*rna 2 python dictionary

列表包含字典,它们的值也是列表。如何从值中打印最大值和国家/地区名称。

data = [{'country':[2,'US']},{'country':[1,'EN']}]
Run Code Online (Sandbox Code Playgroud)

示例:在值中,2 是最大值,国家/地区是“美国”,因此应该打印而不是另一个字典。我运行了下面的代码,但没有得到想要的结果,如何提高效率。

for i in data:
    for m,j in i.items():
        country = j[1][1]
        points = j[1][0]


Example Output:

points = 2
country = 'US'
Run Code Online (Sandbox Code Playgroud)

Sor*_*ary 6

尝试:

data = [{'country': [2, 'US']}, {'country': [1, 'EN']}]

max_dic = max(data, key=lambda x: x['country'][0])
points, country = max_dic['country']

print(country)
print(points)
Run Code Online (Sandbox Code Playgroud)