sorting a list

Jakub Fast kfast at poczta.onet.pl
Thu Apr 29 04:36:30 EDT 2004


>>>I want to sort a list.
[...]
>>>But I am actually looking for an output:
>>>['A','a','D','F','f']
>>>
>>>Is there any module to sort a list this way?

Sean Berry wrote:
 >>>>a = ['A', 'D', 'F', 'a', 'f']
 >>>>a.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
 >>>>a
 >
 > ['a', 'A', 'D', 'f', 'F']
 >
 > this will work too, if lower can come before upper.
 >
 >
 >


If you feel adventurous, try the new sort() in Python 2.4.

Here's the doc:

http://www.python.org/dev/doc/devel/whatsnew/node5.html

Also note that the DSU way will probably be faster than the "general" 
solution (?).

Kuba




More information about the Python-list mailing list