[Python-Dev] Use an empty def as a lambda

Nick Coghlan ncoghlan at gmail.com
Thu Sep 19 23:17:58 CEST 2013


On 20 Sep 2013 07:04, "Joe Pinsonault" <joe.pinsonault at gmail.com> wrote:
>
> I think it's a great idea personally. It's explicit and obvious. "lamda"
is too computer sciencey

This suggestion has been made many times, occasionally with the associated
"must be contained in parentheses when used as an expression" caveat that
is needed to avoid making the language grammar ambiguous at the statement
level.

It mainly runs afoul of two problems:

- reusing the same keyword would make the additional syntactic restrictions
of the expression form even more confusing.
- Guido doesn't particularly like the notion of functions-as-expressions in
the first place (which is why lambda was on thin ice when Python 3 was
being designed), so doesn't actually mind the fact that people avoid using
them because they don't like the keyword.

Cheers,
Nick.

>
> On Sep 19, 2013 1:55 PM, "Ben Gift" <benhgift at gmail.com> wrote:
>>
>> I think the lambda keyword is difficult to understand for many people.
It would be more pythonic to use an empty def call instead.
>>
>> For instance this:
>>
>>     words.sort(key = lambda x: x[2])
>>
>> could look like this:
>>
>>     words.sort(key = def (x): x[2])
>>
>> It's obvious and explicit that we're creating an unnamed, anonymous
function this way.
>>
>> _______________________________________________
>> Python-Dev mailing list
>> Python-Dev at python.org
>> https://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/joe.pinsonault%40gmail.com
>>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130920/290c0ca3/attachment.html>


More information about the Python-Dev mailing list