How to convert country names to ISO 3166-1 alpha-2 values, using python

后端 未结 7 1137
醉酒成梦
醉酒成梦 2020-12-13 13:25

I have a list of countries like:

countries=[\'American Samoa\', \'Canada\', \'France\'...]

I want to convert them like this:



        
7条回答
  •  眼角桃花
    2020-12-13 13:59

    There are a few things to consider with Country Names, especially if using them as search keys. They can be in Title Case (what we think of as normal) or Uppercase (from ISO 3166). Names that include commas or apostrophes might need to be wrapped in quotes. Some names have letters with accents (so non-ASCII). However, there might be a combination that works for you at http://www.dataphyx.com/countrynames/ where you can get CSV lists of ISO Names/IDs in various formats.

提交回复
热议问题