Two questions on lambda:

Terry Reedy tjreedy at udel.edu
Fri Jun 24 22:21:32 CEST 2005


"Xavier Décoret" <Xavier.Decoret at imag.fr> wrote in message 
news:d9gvl9$lo2$1 at trompette.imag.fr...
> Hi,
>
> I cannot find the way to do generic lambda functions using the lambda
> syntax in python. I am probably missing a point.

Thinking of                           lambda args: expression
as more or less abbreviating  def <lambda>(args): return expression
should fill you in.

Two differences:
1. the first is an expression and can be used as such within other 
expressions;
    the second a statement that stands alone.
2. the first will compile (with proper substitutions for 'args' and 
'expression');
    the second will not, because '<lambda>' is not a legal name.

However, in CPython, '<lambda>' *is* the .func_name attribute of 
lambda-defined functions (so they are not quite anonymous;-).

Terry J. Reedy

 






More information about the Python-list mailing list