python将元组作为列表参数

img


输入:
values = [('China', 'CHN'), ('Australia','AUS'), ('New Zealand','NZL'), ('Brazil', 'BRA'), ('Finland', 'FIN'), ('United States of America', 'USA'), ('Singapore', 'SGP')]
a_dict = create_country_alpha3_dictionary(values)
for key in sorted(a_dict ):
print(key, a_dict [key])
输出: Australia AUS
Brazil BRA
China CHN
Finland FIN
New Zealand NZL
Singapore SGP
United States of America USA


def create_country_alpha3_dictionary(values):
    l={}
    for i in values:
            l[i[0]]=i[1]
    return l
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632