Lambda going out of fashion

Stephen Thorne stephen.thorne at
Thu Dec 23 11:47:29 CET 2004

On 23 Dec 2004 00:52:53 -0800, Paul Rubin
<""@nospam.invalid> wrote:
> Alan Gauld <alan.gauld at> writes:
> > readability. Pythonic lambdas are just syntactic sugar in
> > practice,
> Actually it's the other way around: it's named functions that are the
> syntactic sugar.

Not true, you can't re-write

def f():
    raise ValueError, "Don't call f"

as a lambda. Lambdas contain only a single expression. Even the py3k
wiki page ignores this critical difference. A single expression means
no statements of any kind can be included. Assignment, if/elif/else,
while, for, try/except, etc are not catered for in lambdas.

There has been a case in the past for a lambda that contains
statements, but they have been stomped on due to problems with syntax.
I don't like lambdas that have more than a single expression myself
(if it's more complex than "lambda x:baz(", I would prefer to
write a named function).

ultimate-ly yr's.
Stephen Thorne.

More information about the Python-list mailing list