sort accented string
David Fraser
davidf at sjsoft.com
Wed Jun 30 11:09:22 EDT 2004
Peter Otten wrote:
> Laurent wrote:
>
>
>>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 ??
>
>
> From the documentation of the locale module:
>
> """
> strxfrm(string)
>
> Transforms a string to one that can be used for the built-in function cmp(),
> and still returns locale-aware results. This function can be used when the
> same string is compared repeatedly, e.g. when collating a sequence of
> strings.
> """
>
> Peter
>
Note however that you need to transform both strings being compared...
e.g., with a french locale:
>>> 'd' < '\xe9'
True
>>> 'f' < '\xe9'
True
>>> 'd' < locale.strxfrm('\xe9')
False
>>> 'f' < locale.strxfrm('\xe9')
False
>>> locale.strxfrm('f') < locale.strxfrm('\xe9')
False
>>> locale.strxfrm('d') < locale.strxfrm('\xe9')
True
David
More information about the Python-list
mailing list