On Tue, 23 Feb 2021 at 14:10, M.-A. Lemburg <[email protected]> wrote:
>
> The natural way in Python to write an anonymous function would
> be to simply drop the name in a regular function definition:
>
> def (a): return a**2
>
> The lambda notation is less verbose and closer to computer
> science theory, though:
>
> lambda a: a**2
>
> FWIW: I don't understand why people are so unhappy with lambdas.
> There isn't all that much use for lambdas in Python anyway. Most
> of the time, a named function will result in more readable code.

Typically because they are simple expressions like the a**2 you used above.

def a_squared(a):
    return a**2

is way over the top.

Thinking about it, maybe the *real* solution here is to use one of the
"placeholder variable" libraries on PyPI - there's "placeholder" which
I found on a quick search:

    from placeholder import _     # single underscore

    _.age < 18     # lambda obj: obj.age < 18
    _[key] ** 2    # lambda obj: obj[key] ** 2

Some people will hate this sort of thing - probably the same people
who can't see why anyone has a problem with lambda - but it doesn't
need a language change, and it's available now.

I guess I've convinced myself here - we already have shorter
alternatives to lambda, so why add a new built-in one?
Paul
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/64IFHG42SG5Q6Q3AAQVOD7JWE7ZRDTOQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to