if does not evaluate

Terry Reedy tjreedy at udel.edu
Sun Jun 6 06:38:51 CEST 2004

"Jim Newton" <jimka at rdrop.com> wrote in message
news:2if8daFmdreiU1 at uni-berlin.de...
> how do you put an if or a for inside a lambda?

By wrapping them in other functions; otherwise you don't.

lambda *args: expr #abbreviates (minus the function name)
def f(*args): return expr

If your function is more complicated than that, don't try to abbreviate.
Use def.

Terry J. Reedy

More information about the Python-list mailing list