1

I have to no avail, tried to get the Norwegian letters to be sorted in correct order.

import locale
locale.setlocale(locale.LC_ALL,'no_no')
sorted(list('æøå')) # string is already in correct alphabetical order

only to get this:

['å', 'æ', 'ø']

What am I missing? (using Python 3.6.5)

  • So, to sort according to the current locale, taking language-specific rules into account (cmp_to_key is a helper function from functools), try `sorted(list, key=cmp_to_key(locale.strcoll))` – Karn Kumar Oct 03 '18 at 08:05
  • https://stackoverflow.com/questions/11121636/sorting-list-of-string-with-specific-locale-in-python – Tanmay jain Oct 03 '18 at 08:09
  • [here](https://stackoverflow.com/questions/36139/how-to-sort-a-list-of-strings) – Karn Kumar Oct 03 '18 at 08:11

1 Answers1

-1

My guess is that Python uses the unicode values in order to sort characters.

ord('å') # = 229
ord('æ') # = 230
ord('ø') # = 248

So in that sense python correctly orders the values.

Thijs van Ede
  • 861
  • 6
  • 15