sort list doesnt work, key=str still doesnt work

Discussion in 'Python' started by notnorwegian@yahoo.se, May 27, 2008.

  1. Guest

    >>> x
    [',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
    'clever', 'handsome']
    >>> x=sorted([',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse', 'clever', 'handsome'], key=str)
    >>> x

    [',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
    'clever', 'handsome']
    >>>


    what do i need to do?
     
    , May 27, 2008
    #1
    1. Advertising

  2. Dan Bishop Guest

    On May 26, 9:46 pm, wrote:
    > >>> x

    >
    > [',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
    > 'clever', 'handsome']>>> x=sorted([',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse', 'clever', 'handsome'], key=str)
    > >>> x

    >
    > [',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
    > 'clever', 'handsome']
    >
    >
    >
    > what do i need to do?


    x.sort(key=str.upper)
     
    Dan Bishop, May 27, 2008
    #2
    1. Advertising

  3. Dan Upton Guest

    On Mon, May 26, 2008 at 10:46 PM, <> wrote:
    >>>> x

    > [',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
    > 'clever', 'handsome']
    >>>> x=sorted([',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse', 'clever', 'handsome'], key=str)
    >>>> x

    > [',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
    > 'clever', 'handsome']
    >>>>

    >
    > what do i need to do?
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    That's correct behavior for what you gave it. Example from
    http://www.python.org/doc/2.4.3/whatsnew/node12.html :

    >>> sorted('Monty Python') # any iterable may be an input

    [' ', 'M', 'P', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y', 'y']

    It looks like it's sorting based on ASCII value which means all upper
    case letters come before any lower case letter.
     
    Dan Upton, May 27, 2008
    #3
  4. alex23 Guest

    On May 27, 12:46 pm, wrote:
    > what do i need to do?


    Ideally, you need to read some introductory material and stop
    offloading whatever the hell it is you're doing to this group.
     
    alex23, May 27, 2008
    #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. David
    Replies:
    2
    Views:
    480
    Thomas G. Marshall
    Aug 3, 2003
  2. Trevor

    sizeof(str) or sizeof(str) - 1 ?

    Trevor, Apr 3, 2004, in forum: C Programming
    Replies:
    9
    Views:
    636
    CBFalconer
    Apr 10, 2004
  3. Sullivan WxPyQtKinter

    It is fun.the result of str.lower(str())

    Sullivan WxPyQtKinter, Mar 7, 2006, in forum: Python
    Replies:
    5
    Views:
    340
    Tim Roberts
    Mar 9, 2006
  4. Stefan Ram

    str.equals(null) or str==null ?

    Stefan Ram, Jul 31, 2006, in forum: Java
    Replies:
    21
    Views:
    14,721
    Oliver Wong
    Aug 3, 2006
  5. Replies:
    7
    Views:
    745
    Stefan Arentz
    Sep 10, 2007
Loading...

Share This Page