what is lambda used for in real code?

Jp Calderone exarkun at divmod.com
Sat Jan 1 04:17:15 CET 2005

On Fri, 31 Dec 2004 22:09:49 -0500, Terry Reedy <tjreedy at udel.edu> wrote:
> "Adam DePrince" <adam at cognitcorp.com> wrote in message 
> news:1104531721.3724.18.camel at localhost.localdomain...
> > In sort, we must preserve the ability to create an anonymous function
> > simply because we can do so for every other object type, and functions
> > are not special enough to permit this special case.
> Please show me how to create an anonymous type, module, or class, 
> especially with an expression.  Number, sequences, and dicts have easily 
> printable values.  Functions, like classes and module do not*, so 
> definition names act as a standin and as a pointer to the source code that 
> produced the object.  If functions are not special relative to classes and 
> modules, which is the grouping they belong with, then we should get rid of 
> lambda ;-)

    >>> print type('<anon>', (object,), {'foo': lambda self: 'spam'})().foo()


More information about the Python-list mailing list