Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 17th, 2006, 04:25 PM
fdu.xiaojf@gmail.com
Guest
 
Posts: n/a
Default Why there isn't a sort method for array ?

Hi,

It seems that an array acts like an list very much, except it doesn't
have a method sort.


Regards,

  #2  
Old December 17th, 2006, 10:55 PM
Tim Roberts
Guest
 
Posts: n/a
Default Re: Why there isn't a sort method for array ?

"fdu.xiaojf@gmail.com" <fdu.xiaojf@gmail.comwrote:
Quote:
>
>It seems that an array acts like an list very much, except it doesn't
>have a method sort.
What do you mean by "array"? There is no such beast in the Python
language. Do you mean the library module "array"?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
  #3  
Old December 18th, 2006, 12:05 AM
John Machin
Guest
 
Posts: n/a
Default Re: Why there isn't a sort method for array ?


Tim Roberts wrote:
Quote:
"fdu.xiaojf@gmail.com" <fdu.xiaojf@gmail.comwrote:
Quote:

It seems that an array acts like an list very much, except it doesn't
have a method sort.
>
What do you mean by "array"? There is no such beast in the Python
language. Do you mean the library module "array"?
>
Indubitably the OP means objects created by the array function in the
array module. Does that help you answer his question?

Cheers,
John

  #4  
Old December 18th, 2006, 11:05 AM
James Stroud
Guest
 
Posts: n/a
Default Re: Why there isn't a sort method for array ?

John Machin wrote:
Quote:
Tim Roberts wrote:
Quote:
>"fdu.xiaojf@gmail.com" <fdu.xiaojf@gmail.comwrote:
Quote:
>>It seems that an array acts like an list very much, except it doesn't
>>have a method sort.
>What do you mean by "array"? There is no such beast in the Python
>language. Do you mean the library module "array"?
>>
>
Indubitably the OP means objects created by the array function in the
array module. Does that help you answer his question?
>
Cheers,
John
>
Yep. Seems like there should be a sort() for array.array objects,
especially since they implement pop(), insert(), extend(), etc. Also,
all data types corresponding to array typecodes can be compared in a
sort: <http://docs.python.org/lib/module-array.html>.

In the mean time, try

my_sorted_array = array.array(my_array.typecode, sorted(my_array))

James
 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles