Skip to content

Instantly share code, notes, and snippets.

@treyhunner
Created January 21, 2022 18:21
Show Gist options
  • Save treyhunner/8261108b7d333132b544807ee3ffd55a to your computer and use it in GitHub Desktop.
Save treyhunner/8261108b7d333132b544807ee3ffd55a to your computer and use it in GitHub Desktop.
Python script to identify all Unicode flags that represent a different flag when reversed
"""
Script to print all Unicode flag emoji 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 unicodedata
# List copied from this JSON list of ISO 3166-1-alpha-2 data (happens to be valid Python)
# https://www.datahub.io/core/country-list#data
country_data = [{"Code": "AF", "Name": "Afghanistan"},{"Code": "AX", "Name": "\u00c5land Islands"},{"Code": "AL", "Name": "Albania"},{"Code": "DZ", "Name": "Algeria"},{"Code": "AS", "Name": "American Samoa"},{"Code": "AD", "Name": "Andorra"},{"Code": "AO", "Name": "Angola"},{"Code": "AI", "Name": "Anguilla"},{"Code": "AQ", "Name": "Antarctica"},{"Code": "AG", "Name": "Antigua and Barbuda"},{"Code": "AR", "Name": "Argentina"},{"Code": "AM", "Name": "Armenia"},{"Code": "AW", "Name": "Aruba"},{"Code": "AU", "Name": "Australia"},{"Code": "AT", "Name": "Austria"},{"Code": "AZ", "Name": "Azerbaijan"},{"Code": "BS", "Name": "Bahamas"},{"Code": "BH", "Name": "Bahrain"},{"Code": "BD", "Name": "Bangladesh"},{"Code": "BB", "Name": "Barbados"},{"Code": "BY", "Name": "Belarus"},{"Code": "BE", "Name": "Belgium"},{"Code": "BZ", "Name": "Belize"},{"Code": "BJ", "Name": "Benin"},{"Code": "BM", "Name": "Bermuda"},{"Code": "BT", "Name": "Bhutan"},{"Code": "BO", "Name": "Bolivia, Plurinational State of"},{"Code": "BQ", "Name": "Bonaire, Sint Eustatius and Saba"},{"Code": "BA", "Name": "Bosnia and Herzegovina"},{"Code": "BW", "Name": "Botswana"},{"Code": "BV", "Name": "Bouvet Island"},{"Code": "BR", "Name": "Brazil"},{"Code": "IO", "Name": "British Indian Ocean Territory"},{"Code": "BN", "Name": "Brunei Darussalam"},{"Code": "BG", "Name": "Bulgaria"},{"Code": "BF", "Name": "Burkina Faso"},{"Code": "BI", "Name": "Burundi"},{"Code": "KH", "Name": "Cambodia"},{"Code": "CM", "Name": "Cameroon"},{"Code": "CA", "Name": "Canada"},{"Code": "CV", "Name": "Cape Verde"},{"Code": "KY", "Name": "Cayman Islands"},{"Code": "CF", "Name": "Central African Republic"},{"Code": "TD", "Name": "Chad"},{"Code": "CL", "Name": "Chile"},{"Code": "CN", "Name": "China"},{"Code": "CX", "Name": "Christmas Island"},{"Code": "CC", "Name": "Cocos (Keeling) Islands"},{"Code": "CO", "Name": "Colombia"},{"Code": "KM", "Name": "Comoros"},{"Code": "CG", "Name": "Congo"},{"Code": "CD", "Name": "Congo, the Democratic Republic of the"},{"Code": "CK", "Name": "Cook Islands"},{"Code": "CR", "Name": "Costa Rica"},{"Code": "CI", "Name": "C\u00f4te d'Ivoire"},{"Code": "HR", "Name": "Croatia"},{"Code": "CU", "Name": "Cuba"},{"Code": "CW", "Name": "Cura\u00e7ao"},{"Code": "CY", "Name": "Cyprus"},{"Code": "CZ", "Name": "Czech Republic"},{"Code": "DK", "Name": "Denmark"},{"Code": "DJ", "Name": "Djibouti"},{"Code": "DM", "Name": "Dominica"},{"Code": "DO", "Name": "Dominican Republic"},{"Code": "EC", "Name": "Ecuador"},{"Code": "EG", "Name": "Egypt"},{"Code": "SV", "Name": "El Salvador"},{"Code": "GQ", "Name": "Equatorial Guinea"},{"Code": "ER", "Name": "Eritrea"},{"Code": "EE", "Name": "Estonia"},{"Code": "ET", "Name": "Ethiopia"},{"Code": "FK", "Name": "Falkland Islands (Malvinas)"},{"Code": "FO", "Name": "Faroe Islands"},{"Code": "FJ", "Name": "Fiji"},{"Code": "FI", "Name": "Finland"},{"Code": "FR", "Name": "France"},{"Code": "GF", "Name": "French Guiana"},{"Code": "PF", "Name": "French Polynesia"},{"Code": "TF", "Name": "French Southern Territories"},{"Code": "GA", "Name": "Gabon"},{"Code": "GM", "Name": "Gambia"},{"Code": "GE", "Name": "Georgia"},{"Code": "DE", "Name": "Germany"},{"Code": "GH", "Name": "Ghana"},{"Code": "GI", "Name": "Gibraltar"},{"Code": "GR", "Name": "Greece"},{"Code": "GL", "Name": "Greenland"},{"Code": "GD", "Name": "Grenada"},{"Code": "GP", "Name": "Guadeloupe"},{"Code": "GU", "Name": "Guam"},{"Code": "GT", "Name": "Guatemala"},{"Code": "GG", "Name": "Guernsey"},{"Code": "GN", "Name": "Guinea"},{"Code": "GW", "Name": "Guinea-Bissau"},{"Code": "GY", "Name": "Guyana"},{"Code": "HT", "Name": "Haiti"},{"Code": "HM", "Name": "Heard Island and McDonald Islands"},{"Code": "VA", "Name": "Holy See (Vatican City State)"},{"Code": "HN", "Name": "Honduras"},{"Code": "HK", "Name": "Hong Kong"},{"Code": "HU", "Name": "Hungary"},{"Code": "IS", "Name": "Iceland"},{"Code": "IN", "Name": "India"},{"Code": "ID", "Name": "Indonesia"},{"Code": "IR", "Name": "Iran, Islamic Republic of"},{"Code": "IQ", "Name": "Iraq"},{"Code": "IE", "Name": "Ireland"},{"Code": "IM", "Name": "Isle of Man"},{"Code": "IL", "Name": "Israel"},{"Code": "IT", "Name": "Italy"},{"Code": "JM", "Name": "Jamaica"},{"Code": "JP", "Name": "Japan"},{"Code": "JE", "Name": "Jersey"},{"Code": "JO", "Name": "Jordan"},{"Code": "KZ", "Name": "Kazakhstan"},{"Code": "KE", "Name": "Kenya"},{"Code": "KI", "Name": "Kiribati"},{"Code": "KP", "Name": "Korea, Democratic People's Republic of"},{"Code": "KR", "Name": "Korea, Republic of"},{"Code": "KW", "Name": "Kuwait"},{"Code": "KG", "Name": "Kyrgyzstan"},{"Code": "LA", "Name": "Lao People's Democratic Republic"},{"Code": "LV", "Name": "Latvia"},{"Code": "LB", "Name": "Lebanon"},{"Code": "LS", "Name": "Lesotho"},{"Code": "LR", "Name": "Liberia"},{"Code": "LY", "Name": "Libya"},{"Code": "LI", "Name": "Liechtenstein"},{"Code": "LT", "Name": "Lithuania"},{"Code": "LU", "Name": "Luxembourg"},{"Code": "MO", "Name": "Macao"},{"Code": "MK", "Name": "Macedonia, the Former Yugoslav Republic of"},{"Code": "MG", "Name": "Madagascar"},{"Code": "MW", "Name": "Malawi"},{"Code": "MY", "Name": "Malaysia"},{"Code": "MV", "Name": "Maldives"},{"Code": "ML", "Name": "Mali"},{"Code": "MT", "Name": "Malta"},{"Code": "MH", "Name": "Marshall Islands"},{"Code": "MQ", "Name": "Martinique"},{"Code": "MR", "Name": "Mauritania"},{"Code": "MU", "Name": "Mauritius"},{"Code": "YT", "Name": "Mayotte"},{"Code": "MX", "Name": "Mexico"},{"Code": "FM", "Name": "Micronesia, Federated States of"},{"Code": "MD", "Name": "Moldova, Republic of"},{"Code": "MC", "Name": "Monaco"},{"Code": "MN", "Name": "Mongolia"},{"Code": "ME", "Name": "Montenegro"},{"Code": "MS", "Name": "Montserrat"},{"Code": "MA", "Name": "Morocco"},{"Code": "MZ", "Name": "Mozambique"},{"Code": "MM", "Name": "Myanmar"},{"Code": "NA", "Name": "Namibia"},{"Code": "NR", "Name": "Nauru"},{"Code": "NP", "Name": "Nepal"},{"Code": "NL", "Name": "Netherlands"},{"Code": "NC", "Name": "New Caledonia"},{"Code": "NZ", "Name": "New Zealand"},{"Code": "NI", "Name": "Nicaragua"},{"Code": "NE", "Name": "Niger"},{"Code": "NG", "Name": "Nigeria"},{"Code": "NU", "Name": "Niue"},{"Code": "NF", "Name": "Norfolk Island"},{"Code": "MP", "Name": "Northern Mariana Islands"},{"Code": "NO", "Name": "Norway"},{"Code": "OM", "Name": "Oman"},{"Code": "PK", "Name": "Pakistan"},{"Code": "PW", "Name": "Palau"},{"Code": "PS", "Name": "Palestine, State of"},{"Code": "PA", "Name": "Panama"},{"Code": "PG", "Name": "Papua New Guinea"},{"Code": "PY", "Name": "Paraguay"},{"Code": "PE", "Name": "Peru"},{"Code": "PH", "Name": "Philippines"},{"Code": "PN", "Name": "Pitcairn"},{"Code": "PL", "Name": "Poland"},{"Code": "PT", "Name": "Portugal"},{"Code": "PR", "Name": "Puerto Rico"},{"Code": "QA", "Name": "Qatar"},{"Code": "RE", "Name": "R\u00e9union"},{"Code": "RO", "Name": "Romania"},{"Code": "RU", "Name": "Russian Federation"},{"Code": "RW", "Name": "Rwanda"},{"Code": "BL", "Name": "Saint Barth\u00e9lemy"},{"Code": "SH", "Name": "Saint Helena, Ascension and Tristan da Cunha"},{"Code": "KN", "Name": "Saint Kitts and Nevis"},{"Code": "LC", "Name": "Saint Lucia"},{"Code": "MF", "Name": "Saint Martin (French part)"},{"Code": "PM", "Name": "Saint Pierre and Miquelon"},{"Code": "VC", "Name": "Saint Vincent and the Grenadines"},{"Code": "WS", "Name": "Samoa"},{"Code": "SM", "Name": "San Marino"},{"Code": "ST", "Name": "Sao Tome and Principe"},{"Code": "SA", "Name": "Saudi Arabia"},{"Code": "SN", "Name": "Senegal"},{"Code": "RS", "Name": "Serbia"},{"Code": "SC", "Name": "Seychelles"},{"Code": "SL", "Name": "Sierra Leone"},{"Code": "SG", "Name": "Singapore"},{"Code": "SX", "Name": "Sint Maarten (Dutch part)"},{"Code": "SK", "Name": "Slovakia"},{"Code": "SI", "Name": "Slovenia"},{"Code": "SB", "Name": "Solomon Islands"},{"Code": "SO", "Name": "Somalia"},{"Code": "ZA", "Name": "South Africa"},{"Code": "GS", "Name": "South Georgia and the South Sandwich Islands"},{"Code": "SS", "Name": "South Sudan"},{"Code": "ES", "Name": "Spain"},{"Code": "LK", "Name": "Sri Lanka"},{"Code": "SD", "Name": "Sudan"},{"Code": "SR", "Name": "Suriname"},{"Code": "SJ", "Name": "Svalbard and Jan Mayen"},{"Code": "SZ", "Name": "Swaziland"},{"Code": "SE", "Name": "Sweden"},{"Code": "CH", "Name": "Switzerland"},{"Code": "SY", "Name": "Syrian Arab Republic"},{"Code": "TW", "Name": "Taiwan, Province of China"},{"Code": "TJ", "Name": "Tajikistan"},{"Code": "TZ", "Name": "Tanzania, United Republic of"},{"Code": "TH", "Name": "Thailand"},{"Code": "TL", "Name": "Timor-Leste"},{"Code": "TG", "Name": "Togo"},{"Code": "TK", "Name": "Tokelau"},{"Code": "TO", "Name": "Tonga"},{"Code": "TT", "Name": "Trinidad and Tobago"},{"Code": "TN", "Name": "Tunisia"},{"Code": "TR", "Name": "Turkey"},{"Code": "TM", "Name": "Turkmenistan"},{"Code": "TC", "Name": "Turks and Caicos Islands"},{"Code": "TV", "Name": "Tuvalu"},{"Code": "UG", "Name": "Uganda"},{"Code": "UA", "Name": "Ukraine"},{"Code": "AE", "Name": "United Arab Emirates"},{"Code": "GB", "Name": "United Kingdom"},{"Code": "US", "Name": "United States"},{"Code": "UM", "Name": "United States Minor Outlying Islands"},{"Code": "UY", "Name": "Uruguay"},{"Code": "UZ", "Name": "Uzbekistan"},{"Code": "VU", "Name": "Vanuatu"},{"Code": "VE", "Name": "Venezuela, Bolivarian Republic of"},{"Code": "VN", "Name": "Viet Nam"},{"Code": "VG", "Name": "Virgin Islands, British"},{"Code": "VI", "Name": "Virgin Islands, U.S."},{"Code": "WF", "Name": "Wallis and Futuna"},{"Code": "EH", "Name": "Western Sahara"},{"Code": "YE", "Name": "Yemen"},{"Code": "ZM", "Name": "Zambia"},{"Code": "ZW", "Name": "Zimbabwe"}]
# 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]]})"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment