conditionals in lambdas?
Fredrik Lundh
fredrik at effbot.org
Fri Nov 3 14:51:06 EST 2000
Michael P. Soulier wrote
> Hey people. If I want to put conditions in a lambda function, how would I
> go about that?
>
> def test(string):
> if string[:3] == 'yes:
> return 1
> else:
> return 0
>
> I'd like to make something like this a lambda function. Is that possible?
nope. lambdas can only contain simple expressions.
also see:
http://www.python.org/doc/FAQ.html#6.9
6.9. Why can't lambda forms contain statements?
"...the only advantage of using a lambda form instead of
a locally-defined function is that you don't need to invent
a name for the function..."
</F>
More information about the Python-list
mailing list