Why there isn't a sort method for array ?

F

fdu.xiaojf

Hi,

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


Regards,
 
J

John Machin

Tim said:
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
 
J

James Stroud

John said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top