what is lambda used for in real code?

Alex Martelli aleaxit at yahoo.com
Sat Jan 1 21:38:54 CET 2005

Steve Holden <steve at holdenweb.com> wrote:
> >>And you'd create an anonymous type how, exactly?
> > 
> >>>>type('',(),{})
> Indeed. And then you'd insert all the methods as lambdas by ....
> We both know that the Python language framework has enough introspection
> capabilities to do this, but I'm pretty sure you wouldn't try to pretend
> that this would represent a realistic programming style. Or am I wrong?

Calling 'type' to make a new type on the fly is occasionally neat -- not
quite as often as (say) using 'lambda', maybe;-).  Neither should be a
'programming _style_' as opposed to an occasional convenience -- of the
two, lambda has more sensible use cases, but is also more prone to
overuse in practice.  Also, the ability to call 'type' to make a type
adds zero complexity or issues to the language: it's basically zero
cost, just like the ability to call 'int' to make an int, and so on.
This can't be said of lambda, alas: it has a non-zero cost in terms of
(slightly) 'fattening' the language.


More information about the Python-list mailing list