Why there isn't a sort method for array ?

Discussion in 'Python' started by fdu.xiaojf@gmail.com, Dec 17, 2006.

  1. Guest

    Hi,

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


    Regards,
     
    , Dec 17, 2006
    #1
    1. Advertising

  2. Tim Roberts Guest

    "" <> 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,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Dec 17, 2006
    #2
    1. Advertising

  3. John Machin Guest

    Tim Roberts wrote:
    > "" <> 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
     
    John Machin, Dec 17, 2006
    #3
  4. James Stroud Guest

    John Machin wrote:
    > Tim Roberts wrote:
    >> "" <> 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
     
    James Stroud, Dec 18, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Strorm
    Replies:
    19
    Views:
    562
    Michael Strorm
    Apr 20, 2005
  2. Christopher Benson-Manica

    Why isn't there a logical XOR operator?

    Christopher Benson-Manica, Feb 3, 2004, in forum: C Programming
    Replies:
    80
    Views:
    3,397
    CBFalconer
    Feb 6, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,090
    Smokey Grindel
    Dec 2, 2006
  4. Navin
    Replies:
    1
    Views:
    730
    Ken Schaefer
    Sep 9, 2003
  5. Domenico Discepola

    multi-field array sort using Sort::Fields method

    Domenico Discepola, Apr 27, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    306
    Uri Guttman
    Apr 28, 2004
Loading...

Share This Page