Get country code using pycountry from a user input
<p>I am trying to convert a country name to the desired country code.</p>

<p>For example:</p>

<pre><code>United Kingdom : UK
</code></pre>

<p>I have attempted the following:</p>

<pre><code>import pycountry
user_input = raw_input(': ')
mapping = {country.name: country.alpha2 for country in pycountry.countries}
print mapping.get(user_input)
</code></pre>

<p>I believe I may have misunderstood the documentation, since I receive the following error:</p>

<pre><code>    mapping = {country.name: country.alpha2 for country in pycountry.countries}
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycountry/db.py", line 22, in __getattr__
    raise AttributeError
AttributeError
</code></pre>