sort accented string

Peter Otten __peter__ at web.de
Wed Jun 30 09:23:55 EDT 2004


Laurent wrote:

> I'm french and I have a small sorting problem with python (and zope's

Try locale.strcoll():

>>> import locale
>>> locale.setlocale(locale.LC_ALL, "fr_FR")
'fr_FR'
>>> test = list("abéfgz")
>>> test.sort()
>>> test
['a', 'b', 'f', 'g', 'z', '\xe9']
>>> test.sort(locale.strcoll)
>>> test
['a', 'b', '\xe9', 'f', 'g', 'z']
>>>

Peter




More information about the Python-list mailing list