[Python-Dev] Use an empty def as a lambda
rymg19 at gmail.com
Fri Sep 20 00:24:22 CEST 2013
Nice idea, BUT...
Not sure how a parser addition that supports it would go. Imagine this: if
you did a one-line function:
def test(x): print(x)
Python could interpret it two ways:
`def` `name` `lparen` `name` `rparen` `colon`...
OR, it could see it as a lambda-like thingamajig and throw a syntax error.
And, if someone accidentally wrote:
def (x): print(x)
Python should throw a syntax error. But it won't. And it'll take the person
a tad bit to realize he forgot the function name. Whoops.
And, it just would be odd in general.
On Thu, Sep 19, 2013 at 3:54 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)
> could look like this:
> words.sort(key = def (x): x)
> It's obvious and explicit that we're creating an unnamed, anonymous
> function this way.
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev