Perl-Python-a-Day: Sorting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcin 'Qrczak' Kowalczyk

    #16
    Re: Perl-Python-a-Day: Sorting

    Abdulaziz Ghuloum <aghuloum@c-s-remove-dashes.indiana. edu> writes:
    [color=blue]
    > Python FAQs contain an entry to the schwartzian transform.
    >
    > http://www.python.org/doc/faq/progra...form-in-python[/color]

    This entry is obsolete: it should mention the 'key' option of the
    standard sort method.

    --
    __("< Marcin Kowalczyk
    \__/ qrczak@knm.org. pl
    ^^ http://qrnik.knm.org.pl/~qrczak/

    Comment

    • Tim Roberts

      #17
      Re: Perl-Python-a-Day: Sorting

      Marcin 'Qrczak' Kowalczyk <qrczak@knm.org .pl> wrote:
      [color=blue]
      >Abdulaziz Ghuloum <aghuloum@c-s-remove-dashes.indiana. edu> writes:
      >[color=green]
      >> Python FAQs contain an entry to the schwartzian transform.
      >>
      >> http://www.python.org/doc/faq/progra...form-in-python[/color]
      >
      >This entry is obsolete: it should mention the 'key' option of the
      >standard sort method.[/color]

      It should mention it, but not necessarily recommend it.

      I haven't run the numbers in Python, but in Perl, the undecorated sort is
      so well-optimized that the Schwartzian transform is almost always faster
      than passing a custom comparator to the sort function.
      --
      - Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      • Fredrik Lundh

        #18
        Re: Perl-Python-a-Day: Sorting

        Tim Roberts wrote:
        [color=blue][color=green]
        > >This entry is obsolete: it should mention the 'key' option of the
        > >standard sort method.[/color]
        >
        > It should mention it, but not necessarily recommend it.
        >
        > I haven't run the numbers in Python, but in Perl, the undecorated sort is
        > so well-optimized that the Schwartzian transform is almost always faster
        > than passing a custom comparator to the sort function.[/color]

        the "key" option is used for decoration. from the documentation:

        key specifies a function of one argument that is used to extract
        a comparison key from each list element: "key=str.lo wer"

        In general, the key and reverse conversion processes are
        much faster than specifying an equivalent cmp function. This
        is because cmp is called multiple times for each list element
        while key and reverse touch each element only once.

        </F>



        Comment

        • Xah Lee

          #19
          Re: bizarro world (was Re: Python Doc Problem Example: sort() (reprise))


          Bryan wrote:[color=blue]
          > mr. xah... would you be willing to give a lecture at pycon 2006? i'm sure you
          > would draw a huge crowd and a lot of people would like to meet you in person...
          >
          > thanks.[/color]

          I'd be delight to.

          My requirements are: 1 cup of fat-free milk, free, and free pizza.

          Xah
          xah@xahlee.org
          ∑ http://xahlee.org/

          Comment

          • Terry Hancock

            #20
            Re: bizarro world (was Re: Python Doc Problem Example: sort()(reprise) )

            print """\
            On Monday 17 October 2005 02:59 am, Xah Lee wrote:[color=blue]
            >
            > Bryan wrote:[color=green]
            > > mr. xah... would you be willing to give a lecture at pycon 2006? i'm sure you
            > > would draw a huge crowd and a lot of people would like to meet you in person...
            > >
            > > thanks.[/color]
            >
            > I'd be delight to.
            >
            > My requirements are: 1 cup of fat-free milk, free, and free pizza.[/color]
            """.replace('cr owd', 'angry mob')

            ;-D
            --
            Terry Hancock ( hancock at anansispacework s.com )
            Anansi Spaceworks http://www.anansispaceworks.com

            Comment

            • Lucas Raab

              #21
              Re: Perl-Python-a-Day: Sorting

              [snip]
              [color=blue]
              > Thanks. I didn't know there's also a sort function in Python (2.4),
              > besides the method. (i've mentioned your name as acknowledgement at my
              > website essay)[/color]

              [snip]

              With his permission, of course...

              --
              --------------------------
              Lucas Raab
              lvraab"@"earthl ink.net
              dotpyFE"@"gmail .com
              AIM: Phoenix11890
              MSN: dotpyfe "@" gmail.com
              IRC: lvraab
              ICQ: 324767918
              Yahoo: Phoenix11890

              Comment

              Working...