Why there isn't a sort method for array ?
James Stroud
jstroud at mbi.ucla.edu
Mon Dec 18 05:54:10 EST 2006
John Machin wrote:
> Tim Roberts wrote:
>> "fdu.xiaojf at gmail.com" <fdu.xiaojf at gmail.com> 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
More information about the Python-list
mailing list