[Tutor] Sort pointers -

Liam Clarke cyresse at gmail.com
Thu Nov 25 05:48:31 CET 2004


Thanks guys, 

I might hold off on Python 2.4 until it's out of the release candidate
stage (I wonder how that differs from beta testing? Beta testing writ
large?), but the Schwartzian Transform is a wonderfully simple way to
do it, once you know how. Danke Kent.

Like a cryptic crossword, it all makes sense when someone shows you the answer.

And Brian, that link you provided explains the use of a function to
sort,  and also the use of lambda functions in one hit. Brilliant, I'd
been avoiding lambda's for as long as possible.

Oh. And when I say Schwartzian Transform, I think of Terminator and
Decepticons so quite an evil robot sound to it.


Regards,

Liam Clarke



On Wed, 24 Nov 2004 15:31:50 -0500, Brian van den Broek
<bvande at po-box.mcgill.ca> wrote:
> Liam Clarke said unto the world upon 2004-11-24 13:55:
> 
> 
> > Hi all,
> >
> > Thanks Kent. Question - is Python 2.4 release 1 considered a stable release?
> >
> > Brian - Thanks very much for the illuminating functions, they help indeed.
> >
> > So when it returns cmp(x,y) it's returning a negative for x < y, 0 for
> > x == y, and a positive for x > y...
> >
> > eep, a little confused, just trying to understand how Python sorts
> > using that. I may go check out Python 2.4...
> >
> > Regards,
> >
> >
> > Liam Clarke
> >
> >
> > On Wed, 24 Nov 2004 11:30:15 -0500, Brian van den Broek
> > <bvande at po-box.mcgill.ca> wrote:
> >
> >>Kent Johnson said unto the world upon 2004-11-24 06:05:
> 
> <SNIP>
> 
> Hi Liam,
> 
> I'm glad you found my post helpful :-)
> 
> For Kent and the other list-members more knowledgeable than I, I'd be
> curious to know more about the "decorate - sort - undecorate idiom (aka
> Schwartzian Transform)" method. -- Oh, strike that, just got Kent's
> post. Thanks :-) (For what it worth, the names the idiom goes by make it
> sound a good deal more dark than it turns out to be!)
> 
> Liam, in terms of actually using cmp() to make your own sort functions,
> it really isn't too hard. You've just got to remember which of 1 and -1
> get returned in which circumstances. Or, if you are like me, you've got
> to look it up each time :-(
> 
> You can really reduce the work, though. Each time I make a custom cmp()
> function for use with the sort method, I put it into a module -- I call
> mine sorters.py. Having done that, you can promptly forget about the
> details of cmp() again. Just import the desired custom cmp function from
> your sorters module and you are good to go. (Of course, this attitude
> goes a long way to explaining why I have to look up cmp() whenever I
> find the need to write a new comparison function ;-)
> 
> You might also want to check out
> <http://www.amk.ca/python/howto/sorting/sorting.html>.
> 
> Best,
> 
> Brian vdB
> 
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list