I sing the praises of lambda, my friend and savior!

Steven Bethard steven.bethard at gmail.com
Tue Oct 12 00:03:35 EDT 2004


Paul Rubin <"http://phr.cx" <at> NOSPAM.invalid> writes:
> 
> Dave Benjamin <ramen <at> lackingtalent.com> writes:
> > ...
> > "operator.attrgetter()" and "operator.itemgetter()". 
> 
> But why would you want to need to remember such obscure functions?  I
> never heard of any of those.

Couldn't tell if this was a joke or not, so in case it wasn't, attrgetter and 
itemgetter are being introduced in Python 2.4, I believe as a result of the 
sort(key=...) and sorted(key=...) discussions.

> Maybe they should be eliminated instead of
> lambda.  There should be one obvious way to do it, and lambda suffices.

This is the part that really sounded like a joke, but in case it wasn't...

I could write a sort function every time I wanted to sort a list, but why not 
use the one that comes builtin with Python lists?  I could write a strip 
function to remove whitespace from the ends of a string, but why not use the 
one that comes builtin with Python strs?  Likewise, I could write a (lambda) 
function every time I wanted to select an item by index, e.g.

lambda x: x[1]

but if Python has already defined one for me, why would I define it again?

Steve




More information about the Python-list mailing list