[Python-Dev] lambda (x, y):
brett at python.org
Sun Jan 26 01:01:31 CET 2014
On Sat, Jan 25, 2014 at 12:41 AM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:
> Brett Cannon wrote:
>> On Fri, Jan 24, 2014 at 10:50 AM, Ram Rachum <ram at rachum.com <mailto:
>> ram at rachum.com>> wrote:
>> lambda (x, y): whatever
> Part of the rationale in that PEP is that argument unpacking
> can always be replaced by an explicitly named argument and
> an unpacking assignment. No mention is made of the fact that
> you can't do this in a lambda, giving the impression that
> lambdas are deemed second-class citizens that are not worth
> The author was clearly aware of the issue, since a strategy
> is suggested for translation of lambdas by 2to3:
> lambda (x, y): x + y --> lambda x_y: x_y + x_y
> That's a bit on the ugly side for human use, though.
> An alternative would be
> lambda xy: (lambda x, y: x + y)(*xy)
> Whether that's any better is a matter of opinion.
As the author of the PEP and I can say that `lambda (x, y): x + y` can just
as easily be expressed as `lambda x, y: x + y` and then be called by using
*args in the argument list. Anything that gets much fancier typically calls
for a defined function instead of a lambda.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev