Articles
Screencasts
Exercises
Training
Pastebin
Gift
/
Sign Up
Sign In
Script to print all Unicode flag emoji which are also a valid flag when reversed.
""" Script to print all Unicode flag emoji which are also a valid flag when reversed. Output of this script: ๐ฆ๐ฌ (Antigua and Barbuda) reverses to ๐ฌ๐ฆ (Gabon) ๐ฆ๐ฑ (Albania) reverses to ๐ฑ๐ฆ (Lao People's Democratic Republic) ๐ฆ๐ฒ (Armenia) reverses to ๐ฒ๐ฆ (Morocco) ๐ฆ๐ถ (Antarctica) reverses to ๐ถ๐ฆ (Qatar) ๐ฆ๐ธ (American Samoa) reverses to ๐ธ๐ฆ (Saudi Arabia) ๐ฆ๐บ (Australia) reverses to ๐บ๐ฆ (Ukraine) ๐ฆ๐ฟ (Azerbaijan) reverses to ๐ฟ๐ฆ (South Africa) ๐ง๐ง (Barbados) reverses to ๐ง๐ง (Barbados) ๐ง๐ฌ (Bulgaria) reverses to ๐ฌ๐ง (United Kingdom) ๐ง๐ฑ (Saint Barthรฉlemy) reverses to ๐ฑ๐ง (Lebanon) ๐ง๐ธ (Bahamas) reverses to ๐ธ๐ง (Solomon Islands) ๐จ๐จ (Cocos (Keeling) Islands) reverses to ๐จ๐จ (Cocos (Keeling) Islands) ๐จ๐ฑ (Chile) reverses to ๐ฑ๐จ (Saint Lucia) ๐จ๐ฒ (Cameroon) reverses to ๐ฒ๐จ (Monaco) ๐จ๐ณ (China) reverses to ๐ณ๐จ (New Caledonia) ๐จ๐ป (Cape Verde) reverses to ๐ป๐จ (Saint Vincent and the Grenadines) ๐ฉ๐ฒ (Dominica) reverses to ๐ฒ๐ฉ (Moldova, Republic of) ๐ช๐ช (Estonia) reverses to ๐ช๐ช (Estonia) ๐ช๐ฌ (Egypt) reverses to ๐ฌ๐ช (Georgia) ๐ช๐ท (Eritrea) reverses to ๐ท๐ช (Rรฉunion) ๐ช๐ธ (Spain) reverses to ๐ธ๐ช (Sweden) ๐ซ๐ฒ (Micronesia, Federated States of) reverses to ๐ฒ๐ซ (Saint Martin (French part)) ๐ฌ๐ฆ (Gabon) reverses to ๐ฆ๐ฌ (Antigua and Barbuda) ๐ฌ๐ง (United Kingdom) reverses to ๐ง๐ฌ (Bulgaria) ๐ฌ๐ช (Georgia) reverses to ๐ช๐ฌ (Egypt) ๐ฌ๐ฌ (Guernsey) reverses to ๐ฌ๐ฌ (Guernsey) ๐ฌ๐ฒ (Gambia) reverses to ๐ฒ๐ฌ (Madagascar) ๐ฌ๐ณ (Guinea) reverses to ๐ณ๐ฌ (Nigeria) ๐ฌ๐ต (Guadeloupe) reverses to ๐ต๐ฌ (Papua New Guinea) ๐ฌ๐ธ (South Georgia and the South Sandwich Islands) reverses to ๐ธ๐ฌ (Singapore) ๐ฌ๐น (Guatemala) reverses to ๐น๐ฌ (Togo) ๐ฌ๐บ (Guam) reverses to ๐บ๐ฌ (Uganda) ๐ญ๐ฐ (Hong Kong) reverses to ๐ฐ๐ญ (Cambodia) ๐ญ๐ฒ (Heard Island and McDonald Islands) reverses to ๐ฒ๐ญ (Marshall Islands) ๐ญ๐น (Haiti) reverses to ๐น๐ญ (Thailand) ๐ฎ๐ฑ (Israel) reverses to ๐ฑ๐ฎ (Liechtenstein) ๐ฎ๐ณ (India) reverses to ๐ณ๐ฎ (Nicaragua) ๐ฎ๐ธ (Iceland) reverses to ๐ธ๐ฎ (Slovenia) ๐ฐ๐ญ (Cambodia) reverses to ๐ญ๐ฐ (Hong Kong) ๐ฐ๐ฒ (Comoros) reverses to ๐ฒ๐ฐ (Macedonia, the Former Yugoslav Republic of) ๐ฐ๐ต (Korea, Democratic People's Republic of) reverses to ๐ต๐ฐ (Pakistan) ๐ฑ๐ฆ (Lao People's Democratic Republic) reverses to ๐ฆ๐ฑ (Albania) ๐ฑ๐ง (Lebanon) reverses to ๐ง๐ฑ (Saint Barthรฉlemy) ๐ฑ๐จ (Saint Lucia) reverses to ๐จ๐ฑ (Chile) ๐ฑ๐ฎ (Liechtenstein) reverses to ๐ฎ๐ฑ (Israel) ๐ฑ๐ธ (Lesotho) reverses to ๐ธ๐ฑ (Sierra Leone) ๐ฑ๐น (Lithuania) reverses to ๐น๐ฑ (Timor-Leste) ๐ฒ๐ฆ (Morocco) reverses to ๐ฆ๐ฒ (Armenia) ๐ฒ๐จ (Monaco) reverses to ๐จ๐ฒ (Cameroon) ๐ฒ๐ฉ (Moldova, Republic of) reverses to ๐ฉ๐ฒ (Dominica) ๐ฒ๐ซ (Saint Martin (French part)) reverses to ๐ซ๐ฒ (Micronesia, Federated States of) ๐ฒ๐ฌ (Madagascar) reverses to ๐ฌ๐ฒ (Gambia) ๐ฒ๐ญ (Marshall Islands) reverses to ๐ญ๐ฒ (Heard Island and McDonald Islands) ๐ฒ๐ฐ (Macedonia, the Former Yugoslav Republic of) reverses to ๐ฐ๐ฒ (Comoros) ๐ฒ๐ฒ (Myanmar) reverses to ๐ฒ๐ฒ (Myanmar) ๐ฒ๐ด (Macao) reverses to ๐ด๐ฒ (Oman) ๐ฒ๐ต (Northern Mariana Islands) reverses to ๐ต๐ฒ (Saint Pierre and Miquelon) ๐ฒ๐ธ (Montserrat) reverses to ๐ธ๐ฒ (San Marino) ๐ฒ๐น (Malta) reverses to ๐น๐ฒ (Turkmenistan) ๐ฒ๐บ (Mauritius) reverses to ๐บ๐ฒ (United States Minor Outlying Islands) ๐ฒ๐ฟ (Mozambique) reverses to ๐ฟ๐ฒ (Zambia) ๐ณ๐จ (New Caledonia) reverses to ๐จ๐ณ (China) ๐ณ๐ฌ (Nigeria) reverses to ๐ฌ๐ณ (Guinea) ๐ณ๐ฎ (Nicaragua) reverses to ๐ฎ๐ณ (India) ๐ณ๐ต (Nepal) reverses to ๐ต๐ณ (Pitcairn) ๐ด๐ฒ (Oman) reverses to ๐ฒ๐ด (Macao) ๐ต๐ฌ (Papua New Guinea) reverses to ๐ฌ๐ต Guadeloupe) ๐ต๐ฐ (Pakistan) reverses to ๐ฐ๐ต (Korea, Democratic People's Republic of) ๐ต๐ฒ (Saint Pierre and Miquelon) reverses to ๐ฒ๐ต (Northern Mariana Islands) ๐ต๐ณ (Pitcairn) reverses to ๐ณ๐ต (Nepal) ๐ถ๐ฆ (Qatar) reverses to ๐ฆ๐ถ (Antarctica) ๐ท๐ช (Rรฉunion) reverses to ๐ช๐ท (Eritrea) ๐ท๐ธ (Serbia) reverses to ๐ธ๐ท (Suriname) ๐ธ๐ฆ (Saudi Arabia) reverses to ๐ฆ๐ธ (American Samoa) ๐ธ๐ง (Solomon Islands) reverses to ๐ง๐ธ (Bahamas) ๐ธ๐ช (Sweden) reverses to ๐ช๐ธ (Spain) ๐ธ๐ฌ (Singapore) reverses to ๐ฌ๐ธ (South Georgia and the South Sandwich Islands) ๐ธ๐ฎ (Slovenia) reverses to ๐ฎ๐ธ (Iceland) ๐ธ๐ฑ (Sierra Leone) reverses to ๐ฑ๐ธ (Lesotho) ๐ธ๐ฒ (San Marino) reverses to ๐ฒ๐ธ (Montserrat) ๐ธ๐ท (Suriname) reverses to ๐ท๐ธ (Serbia) ๐ธ๐ธ (South Sudan) reverses to ๐ธ๐ธ (South Sudan) ๐น๐ฌ (Togo) reverses to ๐ฌ๐น (Guatemala) ๐น๐ญ (Thailand) reverses to ๐ญ๐น (Haiti) ๐น๐ฑ (Timor-Leste) reverses to ๐ฑ๐น (Lithuania) ๐น๐ฒ (Turkmenistan) reverses to ๐ฒ๐น (Malta) ๐น๐น (Trinidad and Tobago) reverses to ๐น๐น (Trinidad and Tobago) ๐บ๐ฆ (Ukraine) reverses to ๐ฆ๐บ (Australia) ๐บ๐ฌ (Uganda) reverses to ๐ฌ๐บ (Guam) ๐บ๐ฒ (United States Minor Outlying Islands) reverses to ๐ฒ๐บ (Mauritius) ๐ป๐จ (Saint Vincent and the Grenadines) reverses to ๐จ๐ป (Cape Verde) ๐ฟ๐ฆ (South Africa) reverses to ๐ฆ๐ฟ (Azerbaijan) ๐ฟ๐ฒ (Zambia) reverses to ๐ฒ๐ฟ (Mozambique) """ import json from urllib.request import urlopen import unicodedata # JSON list of ISO 3166-1-alpha-2 data country_data_url = "https://www.datahub.io/core/country-list/r/data.json" country_data = json.loads(urlopen(country_data_url).read().decode()) # Map country codes to country names countries = {country["Code"]: country["Name"] for country in country_data} # Find all country codes that are valid when reversed reversible_codes = sorted(code for code in countries if code[::-1] in countries) def flag_for(code): """Return unicode flag emoji given a 2-digit country code.""" return "".join( unicodedata.lookup(f"REGIONAL INDICATOR SYMBOL LETTER {char}") for char in code ) # Print each flag and country name and its valid reverse flag and country name # Note: some flags are their own reverse (due to palindrome codes like TT) # Note: each countries is printed twice (once as forward, once as reverse) for code in reversible_codes: print( f"{flag_for(code)} ({countries[code]})", "reverses to", f"{flag_for(code[::-1])} ({countries[code[::-1]]})", )
255 views
Copy
Code copied
pym.dev/p/2w4by/
URL copied
Need to share some Python code?
New Python snippet