lambda (and reduce) are valuable
bonono at gmail.com
bonono at gmail.com
Wed Dec 14 21:56:56 EST 2005
More information about the Python-list mailing list
Wed Dec 14 21:56:56 EST 2005
- Previous message (by thread): lambda (and reduce) are valuable
- Next message (by thread): how does exception mechanism work?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Marc 'BlackJack' Rintsch wrote: > 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)) > Though I find the lambda form easier for me to understand but itemgetter should be the preferred way as it should have some performance advantage and sort are those kind of functions that need it, in general.
- Previous message (by thread): lambda (and reduce) are valuable
- Next message (by thread): how does exception mechanism work?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list