[Python-Dev] lambda (x, y):

Raymond Hettinger raymond.hettinger at gmail.com
Sun Jan 26 03:42:43 CET 2014


On Jan 25, 2014, at 4:01 PM, Brett Cannon <brett at python.org> wrote:

> 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.

I think that is an over-simplification.  The argument unpacking was handy
in a number of situations where *args wouldn't suffice:

   lambda (px, py), (qx, qy): ((px - qx) ** 2 + (py - qy) ** 2) ** 0.5

IIRC, the original reason for the change was that it simplified the compiler a bit,
not that it was broken or not useful.

Taking-out tuple unpacking might have been a good idea for the reasons listed
in the PEP, but we shouldn't pretend that it didn't cripple some of the use cases
for lambda where some of the arguments came in as tuples (host/port pairs,
x-y coordinates, hue-saturation-luminosity, month-day-year, etc).


Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140125/7bdcce0c/attachment.html>


More information about the Python-Dev mailing list