我有以下字典:詞典/名單最大的關鍵
[{'country': 'Armenia', 'population': '3026048'}, {'country': 'Angola', 'population': '25830958'}, {'country': 'Algeria', 'population': '40375954'}, {'country': 'Andorra', 'population': '69165'}, {'country': 'Anguilla', 'population': '14763'}, {'country': 'American Samoa', 'population': '55602'}, {'country': 'Aruba', 'population': '104263'}, {'country': 'Argentina', 'population': '43847277'}, {'country': 'Afghanistan', 'population': '33369945'}, {'country': 'Azerbaijan', 'population': '9868447'}, {'country': 'Australia', 'population': '24309330'}, {'country': 'Antigua and Barbuda', 'population': '92738'}, {'country': 'Albania', 'population': '2903700'}, {'country': 'Austria', 'population': '8569633'}]
和下面的列表
[['Andorra', '69165'], ['Afghanistan', '33369945'], ['Algeria', '40375954'], ['American Samoa', '55602'], ['Aruba', '104263'], ['Armenia', '3026048'], ['Angola', '25830958'], ['Azerbaijan', '9868447'], ['Antigua and Barbuda', '92738'], ['Australia', '24309330'], ['Albania', '2903700'], ['Argentina', '43847277'], ['Anguilla', '14763'], ['Austria', '8569633']]
我怎樣才能提取人口最多的國家的國名(在第二值每個子列表)
您可以爲列表或字典提供解決方案。
'import operator','max(my_dict,key = operator.itemgetter('population'))''。請注意,你的「字典」實際上是一個字典列表,而你的「列表」是一個列表清單 – inspectorG4dget