1- default_country_name = "XX"
1+ # Default country code.
2+ default_code = "XX"
23
4+ # Mapping of country names to alpha-2 codes.
35is_3166_1 = {
46 "Afghanistan" : "AF" ,
57 "Åland Islands" : "AX" ,
254256
255257# Mapping of alternative names, spelling, typos to the names of countries used
256258# by the ISO 3166-1 norm
257- country_name_synonyms = {
259+ synonyms = {
258260 "Mainland China" : "China" ,
259261 "Czechia" : "Czech Republic" ,
260262 "South Korea" : "Korea, Republic of" ,
268270 "Iran" : "Iran, Islamic Republic of" ,
269271 "Saint Barthelemy" : "Saint Barthélemy" ,
270272 "Palestine" : "Palestine, State of" ,
273+ "Vatican City" : "Holy See (Vatican City State)" ,
271274 # "Others" has no mapping
272275}
273276
@@ -280,10 +283,9 @@ def country_code(country):
280283 if country in is_3166_1 :
281284 return is_3166_1 [country ]
282285 else :
283- if country in country_name_synonyms :
284- synonym = country_name_synonyms [country ]
286+ if country in synonyms :
287+ synonym = synonyms [country ]
285288 return is_3166_1 [synonym ]
286289 else :
287- print ("No country_code found for '" + country + "'. Using '"
288- + default_country_name + "'" )
289- return default_country_name
290+ print ("No country_code found for '" + country + "'. Using '" + default_code + "'" )
291+ return default_code
0 commit comments