sort accented string

Laurent laurentpointrahuel at clubtiretinternet.fr
Wed Jun 30 09:47:10 EDT 2004


Peter what about using this kind of tip with cmp() built-in ??

def myCompare(self,a,b):
        cmp(a,b)

with a and b being french accented chars ???

Any idea ??

Thanks again.

Peter Otten wrote:

> 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