Skip to content

Instantly share code, notes, and snippets.

@petri
Last active October 22, 2018 18:40
Show Gist options
  • Save petri/6b582a321232c078cbce2550a6886158 to your computer and use it in GitHub Desktop.
Save petri/6b582a321232c078cbce2550a6886158 to your computer and use it in GitHub Desktop.
Common disambiguated country names
"""
An attempt to produce a good enough list of commonly understandable country names
from pycountry straight-jacket names. Thus country names produced are without
prefixes such as "Republic of", and are also disambiguated from one another
(British & US Virgin Islands and Republic & Democratic Republic of Congo).
People living in the two countries both known as Congo call their country
either Congo-Kinshasa or Congo-Brazzaville, ie. adding the name of the capital;
we use that convention as an incremental means for additional disambiguation.
Also, liberty is taken to call Lao People's Democratic Republic just Laos, and
use the commonly known names North and South Korea, rather than the official
ones.
"""
import pycountry
for c in pycountry.countries:
if c.name.startswith("Virgin Islands"):
print(c.official_name)
elif c.alpha_2 == "KR":
print("South Korea")
elif c.alpha_2 == "KP":
print("North Korea")
elif c.alpha_2 == "LA":
print("Laos")
elif c.alpha_2 == "CD":
name = c.name.split(',')
name.reverse()
print (' '.join(name).strip() + " (%s)" % "Congo-Kinshasa")
elif c.alpha_2 == "CG":
print(c.official_name + " (%s)" % "Congo-Brazzaville")
elif ',' in c.name:
print(c.name.split(',')[0])
else:
print(c.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment