Created
July 23, 2018 18:31
-
-
Save bee-san/57d42d72f95354fe3f86241a443a416a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Taken from page 70 chapter 3 of Fluent Python by Luciano Ramalho | |
| DIAL_CODES = [ | |
| (86, 'China'), | |
| (91, 'India'), | |
| (1, 'United States'), | |
| (62, 'Indonesia'), | |
| (55, 'Brazil'), | |
| (92, 'Pakistan'), | |
| (880, 'Bangladesh'), | |
| (234, 'Nigeria'), | |
| (7, 'Russia'), | |
| (81, 'Japan'), | |
| ] | |
| >>> country_code = {country: code for code, country in DIAL_CODES} | |
| >>> country_code | |
| {'Brazil': 55, 'Indonesia': 62, 'Pakistan': 92, 'Russia': 7, 'China': 86, 'United States': 1, 'Japan': 81, 'India': 91, 'Nigeria': 234, 'Bangladesh': 880} | |
| >>> {code: country.upper() for country, code in country_code.items() if code < 66} | |
| {1: 'UNITED STATES', 7: 'RUSSIA', 62: 'INDONESIA', 55: 'BRAZIL'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment