Schwartzian Transform (was Re: Sort)
sh at ttsoftware.co.uk
Thu Dec 7 13:20:39 CET 2000
On Wed, 6 Dec 2000 14:16:53 -0500, "Steven D. Majewski"
<sdm7g at Virginia.EDU> wrote:
>On Wed, 6 Dec 2000, Alex Martelli wrote:
>> The technique is named after its inventor Randall
>> Schwartz, who thought it up in the context of Perl
>> (but it works even better in Python:-).
>This is however, a pretty ancient Python idiom, so I wonder
>about attributing it to Randall's invention.
Even older still, I think. I'd have to double check, but I swear
similar tricks were used decades ago in normal 3GLs, to cope with
library sort functions that didn't take parameters. Certainly I used
it in 1988, at least 8 years before I ever heard of Perl or Python.
Some people somehow seem to get their names associated with
restatements of the obvious.
I have to say I'm a little surprised by the scale of the speedup, but
even so I'd usually not bother. The lambda method is clearer, and
works just as well unless you're sorting a lot of data. If I was
worried about the difference between 0.0353952707969 and
0.220513718779 seconds, I wouldn't be using a scripting language.
Home : steve at lurking.demon.co.uk
Work : sh at ttsoftware.co.uk
More information about the Python-list