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

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Sep 20 00:19:47 CEST 2013


On Thu, Sep 19, 2013 at 4:54 PM, Ben Gift <benhgift at gmail.com> wrote:

> It would be more pythonic to use an empty def call instead.


No, it won't.  Python draws a very strong distinction between expressions
and statements.  This line has been blurred somewhat with the advent of
 comprehensions and the if-else expression, but it would still require more
benefit than three characters in a keyword saving to allow def use in both
statements and expressions.

The following, for example, does not look pythonic at all:

*def* transform(*seq*, *func*=*def*(*x*):*x*):
      ...

(Note that I attempted to emulate syntax highlighting to make my point.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130919/0ee8e0fd/attachment.html>


More information about the Python-Dev mailing list