Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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?
 
Reply With Quote
 
 
 
 
Dan Bishop
Guest
Posts: n/a
 
      05-27-2008
On May 26, 9:46*pm, notnorweg...@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?


x.sort(key=str.upper)
 
Reply With Quote
 
 
 
 
Dan Upton
Guest
Posts: n/a
 
      05-27-2008
On Mon, May 26, 2008 at 10:46 PM, <> 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.
 
Reply With Quote
 
alex23
Guest
Posts: n/a
 
      05-27-2008
On May 27, 12:46 pm, notnorweg...@yahoo.se wrote:
> what do i need to do?


Ideally, you need to read some introductory material and stop
offloading whatever the hell it is you're doing to this group.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
jsf core tag <f:param> doesnt work with <h:commandButton> but work with <h:commandLink> Janaka Perera Java 0 10-29-2007 08:10 PM
Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute cjt22@bath.ac.uk Python 7 09-10-2007 11:10 AM
PC doesnt boot first time and doesnt shutdown dann Computer Support 6 08-21-2006 07:31 AM
why it seems that std::list::erase() doesnt free objects in a list, if the latter holds pointers to them? jimjim C++ 18 04-12-2004 09:12 PM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57