Hellerick_Ferlibay

CustomAlphabetiser.py

Aug 22nd, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.01 KB | None | 0 0
  1. List = [
  2.     "Afghanistan", "Albania", "Algeria", "Andorra", "Angola",
  3.     "Antigua and Barbuda", "Argentina", "Armenia", "Australia",
  4.     "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh",
  5.     "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan",
  6.     "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei",
  7.     "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cambodia",
  8.     "Cameroon", "Canada", "Cape Verde", "Central African Republic",
  9.     "Chad", "Chile", "China", "Colombia", "Comoros",
  10.     "Congo, Republic of the", "Costa Rica", "Croatia", "Cuba", "Cyprus",
  11.     "Czech Republic", "Congo, Democratic Republic of the", "Denmark",
  12.     "Djibouti", "Dominica", "Dominican Republic", "East Timor",
  13.     "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
  14.     "Estonia", "Ethiopia", "Fiji", "Finland", "France", "Gabon",
  15.     "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Guatemala",
  16.     "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hungary",
  17.     "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland",
  18.     "Israel", "Italy", "Ivory Coast", "Jamaica", "Japan", "Jordan",
  19.     "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
  20.     "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein",
  21.     "Lithuania", "Luxembourg", "Macedonia", "Madagascar", "Malawi",
  22.     "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
  23.     "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova",
  24.     "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique",
  25.     "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand",
  26.     "Nicaragua", "Niger", "Nigeria", "North Korea", "Norway", "Oman",
  27.     "Pakistan", "Palau", "Palestine", "Panama", "Papua New Guinea",
  28.     "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar",
  29.     "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis",
  30.     "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa",
  31.     "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal",
  32.     "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia",
  33.     "Slovenia", "Solomon Islands", "Somalia", "South Africa",
  34.     "South Korea", "South Sudan", "Spain", "Sri Lanka", "Sudan",
  35.     "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan",
  36.     "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga",
  37.     "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
  38.     "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates",
  39.     "United Kingdom", "United States", "Uruguay", "Uzbekistan",
  40.     "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Yemen",
  41.     "Zambia", "Zimbabwe"]
  42.  
  43. order = 'EFMIRNOVQADTWKLUBPCJYSHGXZ'
  44.  
  45. orderdict = dict(zip(order, list(range(len(order)))))
  46.  
  47. def orderweight(name):
  48.     name = name.upper()
  49.     name = ''.join([s for s in list(name) if s in list(order)])
  50.     weight = 0.0
  51.     for i in range(len(name)):
  52.         weight = weight + float(orderdict[name[i]])/len(order)**i
  53.     return weight
  54.  
  55. result = sorted(List, key=orderweight)
  56.  
  57. print (result)
Advertisement
Add Comment
Please, Sign In to add comment