tags:

views:

119

answers:

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?

+1  A: 

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

Lukáš Lalinský
A: 

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]

Working program.

PS: Lukáš Lalinský thx for your answer.

Gašper