sort list doesnt work, key=str still doesnt work

Dan Upton upton at virginia.edu
Mon May 26 22:58:30 EDT 2008


On Mon, May 26, 2008 at 10:46 PM,  <notnorwegian at yahoo.se> wrote:
>>>> x
> [',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
> 'clever', 'handsome']
>>>> x=sorted([',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse', 'clever', 'handsome'], key=str)
>>>> x
> [',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
> 'clever', 'handsome']
>>>>
>
> what do i need to do?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

That's correct behavior for what you gave it.  Example from
http://www.python.org/doc/2.4.3/whatsnew/node12.html :

>>> sorted('Monty Python')          # any iterable may be an input
[' ', 'M', 'P', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y', 'y']

It looks like it's sorting based on ASCII value which means all upper
case letters come before any lower case letter.



More information about the Python-list mailing list