Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Why there isn't a sort method for array ?

Reply
Thread Tools

Why there isn't a sort method for array ?

 
 
fdu.xiaojf@gmail.com
Guest
Posts: n/a
 
      12-17-2006
Hi,

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


Regards,

 
Reply With Quote
 
 
 
 
Tim Roberts
Guest
Posts: n/a
 
      12-17-2006
"(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
>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, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      12-17-2006

Tim Roberts wrote:
> "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> >
> >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

 
Reply With Quote
 
James Stroud
Guest
Posts: n/a
 
      12-18-2006
John Machin wrote:
> Tim Roberts wrote:
>> "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>>> 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
 
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
Chris Pine tutorial assistance chapter 7 sort data without use of.sort method jgheal@googlemail.com Ruby 9 11-27-2008 07:36 PM
Chris Pine tutorial assistance chapter 7 sort data without use of.sort method jgheal@googlemail.com Ruby 0 11-24-2008 11:21 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
multi-field array sort using Sort::Fields method Domenico Discepola Perl Misc 6 04-28-2004 04:28 AM
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