Velocity Reviews > sort list doesnt work, key=str still doesnt work

# sort list doesnt work, key=str still doesnt work

notnorwegian@yahoo.se
Guest
Posts: n/a

 05-27-2008
>>> 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?

Dan Bishop
Guest
Posts: n/a

 05-27-2008
On May 26, 9:46*pm, (E-Mail Removed) 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?

x.sort(key=str.upper)

Dan Upton
Guest
Posts: n/a

 05-27-2008
On Mon, May 26, 2008 at 10:46 PM, <(E-Mail Removed)> 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.

alex23
Guest
Posts: n/a

 05-27-2008
On May 27, 12:46 pm, (E-Mail Removed) wrote:
> what do i need to do?

Ideally, you need to read some introductory material and stop