字典推导式

#字典推倒
dial_codes = [(86,'china'),(91,'india'),(1,'us'),(62,'indos'),(55,'brazil'),(92,'pakitan'),(7,'russia')]

country_code = {country:code for code,country in dial_codes} # 字典推导式
print(country_code) # {'china': 86, 'india': 91, 'us': 1, 'indos': 62, 'brazil': 55, 'pakitan': 92, 'russia': 7}

print({code:country.upper() for country,code in country_code.items() if code <66})#{1: 'US', 62: 'INDOS', 55: 'BRAZIL', 7: 'RUSSIA'}

 

posted @ 2018-01-12 18:10  Erick-LONG  阅读(241)  评论(0编辑  收藏  举报