why syntax change in lambda
Oscar Benjamin
oscar.j.benjamin at gmail.com
Wed Sep 11 09:11:22 EDT 2013
On 11 September 2013 14:03, Neal Becker <ndbecker2 at gmail.com> wrote:
> In py2.7 this was accepted, but not in py3.3. Is this intentional? It seems to
> violate the 'principle' that extraneous parentheses are usually allowed/ignored
>
> In [1]: p = lambda x: x
>
> In [2]: p = lambda (x): x
> File "<ipython-input-2-2b94675a98f1>", line 1
> p = lambda (x): x
> ^
> SyntaxError: invalid syntax
I guess it's related to the removal of auto-unpacking of arguments. i.e. in 2.x:
>>> f = lambda (x, y), z: (x, y, z)
>>> f([1, 2], 3)
(1, 2, 3)
However this was removed in 3.x so
>>> f = lambda (x, y), z: (x, y, z)
File "<stdin>", line 1
f = lambda (x, y), z: (x, y, z)
^
SyntaxError: invalid syntax
Removing that feature would allow a simplification of the lambda
syntax that would have no need to admit any kind of brackets.
Oscar
More information about the Python-list
mailing list