擅长:python、mysql、java
<p>您可以使用这个csv文件:<a href="http://geohack.net/gis/wikipedia-iso-country-codes.csv" rel="noreferrer"> country code list into a CSV</a>。</p>
<pre><code>In [41]: import csv
In [42]: dic = {}
In [43]: with open("wikipedia-iso-country-codes.csv") as f:
file= csv.DictReader(f, delimiter=',')
for line in file:
dic[line['English short name lower case']] = line['Alpha-2 code']
....:
In [44]: countries = ['American Samoa', 'Canada', 'France']
In [45]: [dic[x] for x in countries]
Out[45]: ['AS', 'CA', 'FR']
</code></pre>
<p>再多几个<a href="https://gis.stackexchange.com/questions/1047/full-list-of-iso-alpha-2-and-iso-alpha-3-country-codes">alternatives</a>。</p>