가능한 중복 : I는 알파벳 순서로 일부 단어를 분류하기 위해 노력하고있어
Python not sorting unicode properly. Strcoll doesn't help.정렬 문자열
. 나는 단어가 여기가 정의와 같은 순서로 인쇄되지만 것을 기대하고 있습니다
#!/opt/local/bin/python2.7
# -*- coding: utf-8 -*-
import locale
# Make sure the locale is in french
locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
print "locale: " + str(locale.getlocale())
# The words are in alphabetical order
words = ["liche", "lichée", "lichen", "lichénoïde", "licher", "lichoter"]
for word in sorted(words, cmp=locale.strcoll):
print word.decode("string-escape")
내가 무엇을 얻을 : 여기에 내가 그것을 어떻게
locale: ('fr_FR', 'UTF8')
liche
lichen
licher
lichoter
lichée
lichénoïde
é 문자는 마치 z보다 큰 것으로 취급됩니다.
나는 locale.strcoll
이 문자열을 어떻게 비교하는지 오해하고있는 것 같습니다. 단어를 사전 순으로 정렬하려면 어떤 비교 함수를 사용해야합니까?
제대로 작동하는 것 같습니다. 나는 "z"를 볼 수 없다. –
이 예제에는'z'가 없지만'é'는 알파벳 순서가 아닌'o' 다음에옵니다. – 0xced
2.6.4에서 올바르게 작동합니다. –