My application needs to handle different language sorts. Do you know a
way to apply strxfrm dynamically i.e. without setting the locale?
Tuomas
Neil Cerutti wrote:
> On 2006-10-16, Ron Adam <rrr at ronadam.com> wrote:
>>>I have several applications where I want to sort lists in
>>alphabetical order. Most examples of sorting usually sort on
>>the ord() order of the character set as an approximation. But
>>that is not always what you want.
>>> Check out strxfrm in the locale module.
>>>>>>a = ["Neil", "Cerutti", "neil", "cerutti"]
>>>>a.sort()
>>>>a
>> ['Cerutti', 'Neil', 'cerutti', 'neil']
>>>>>import locale
>>>>locale.setlocale(locale.LC_ALL, '')
>> 'English_United States.1252'
>>>>>a.sort(key=locale.strxfrm)
>>>>a
>> ['cerutti', 'Cerutti', 'neil', 'Neil']
>