sorting a list
Matthias Huening
mhuening at zedat.fu-berlin.de
Thu Apr 29 05:03:03 EDT 2004
ketulp_baroda at yahoo.com wrote in news:f046efac.0403091513.3b392074
@posting.google.com:
> But I am actually looking for an output:
> ['A','a','D','F','f']
>
> Is there any module to sort a list this way?
You could use the locale module to sort according to locale
conventions:
>>> import locale
>>> locale.setlocale(locale.LC_ALL,"")
'German_Germany.1252'
>>> a = ['A', 'D', 'F', 'a', 'f', 'ä']
>>> def sortDeutsch(a,b):
return locale.strcoll(a[0], b[0])
>>> a.sort(sortDeutsch)
>>> a
['a', 'A', '\xe4', 'D', 'f', 'F']
>>>
Matthias
More information about the Python-list
mailing list