pycountry icon indicating copy to clipboard operation
pycountry copied to clipboard

Get alpha_2 with alpha_3

Open glosophy opened this issue 3 years ago • 1 comments

I currently have countries with their corresponding ISO3 code. How can I look up countries' ISO2 code with the ISO3?

glosophy avatar Feb 17 '22 19:02 glosophy

what about getting the language via alpha_2 and then reading the alpha_3 attribute?

>> pycountry.languages.get(alpha_3='eng').alpha_2
'en'

benelgiac avatar Mar 10 '22 14:03 benelgiac

@glosophy please see below code @benelgiac it is even easier than that.

>>> import pycountry
>>> alpha_3 = 'USA'
>>> country = pycountry.countries.get(alpha_3=alpha_3)
>>> country.alpha_2
'US'

nschimmoller avatar Dec 08 '23 19:12 nschimmoller