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

2 Answers 2

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]
Sign up to request clarification or add additional context in comments.

1 Comment

I know this is an old question, but it doesn't work for me on Python 2.7.3. I get: a ć č aa ab B c d
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.