Lambdaizing Python Code

Fernando Pérez fperez528 at yahoo.com
Sat Sep 28 21:54:44 EDT 2002


Gerson Kurz wrote:

> A really usefull study ... NOT.
> 
> http://p-nand-q.com/e/quicksort_lambda.html
> 
> also known as "making Guido regret he put lambda in THE BEST
> PROGRAMMING LANGUAGE IN THE WORLD(TM)".

Now, as an excersise in sillyness it's funny. However, a more reasonable 
rewriting as a lambda can be found at:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66473

And is a simple one-liner:

q=lambda x:(lambda o=lambda s:[i for i in x if cmp(i,x[0])==s]:len(x)>1 \
  and q(o(-1))+o(0)+q(o(1)) or x)()

Granted, for a quicksort I'd _much_ rather use a normal functional form. But 
this doesn't mean that a lambda form has to be the monstrosity depicted in 
that page :) I do take my hat off to whoever wrote it: just the fact that it 
works at all is an accomplishment in and of itself.

Cheers,

f.



More information about the Python-list mailing list