2
data = [unicode('č', "cp1250"),
        unicode('d', "cp1250"),
        unicode('a', "cp1250")]

data.sort(key=unicode.lower) 

for x in range(0,len(data)):
    print data[x].encode("cp1250")

and I get:

a
d
č

It should be:

a
č
d

Slovenia Alphabet goes like: a b c č d e f g.....

I'm using WIN XP(Active code page: 852 - Slovenia). Can you help me?

Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
Gašper
  • 119
  • 1
  • 1
  • 7

2 Answers2

3

I solved this problem an now have a working program:

import locale
locale.setlocale(locale.LC_ALL, 'slovenian')
data = ['č', 'ab', 'aa', 'a', 'd', 'ć', 'B', 'c']
data.sort(key=locale.strxfrm)
print "Sorted..."
for x in range(0,len(data)):
    print data[x]
Kev
  • 118,037
  • 53
  • 300
  • 385
Gašper
  • 119
  • 1
  • 1
  • 7
1

See the locale module for language-aware sorting. Especially the strcoll and strxfrm functions.

Lukáš Lalinský
  • 40,587
  • 6
  • 104
  • 126