lambda (and reduce) are valuable
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Wed Dec 14 19:03:10 EST 2005
In <dnmobd$5a0$1 at rumours.uwaterloo.ca>, Christopher Subich wrote:
> Chris Mellon wrote:
>> functions with real names is crucial to maintainable code. The only
>> reason to ever use a lamdba in Python is because you don't want to
>> give a function a name, and that is just not a compelling use case for
>> GUI events.
>
> Ah, but that neglects the sheer utility of delayed-evaluation
> expressions. Consider the key= parameter to list.sort, et. al:
>
> complicated_list.sort(key=lambda x: x[3])
This can be written as::
from operator import itemgetter
complicated_list.sort(key=itemgetter(3))
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list