Reputation: 381
I want to implement the function via a lambda expression as follows:
Instead of this:
def f(x, y, z):
return x + 1, y * 2, z * 3
I want to use a lambda expression, like this:
f = lambda x, y, z: x + 1, y * 2, z * 3
The stacktrace:
*Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'y' is not defined*
Why is this causing an error? How can this be done?
Upvotes: 2
Views: 6092
Reputation: 15310
Your tuple is not binding correctly - the lambda is ending at the first comma. Put parens around the tuple:
f=lambda x,y,z: (x+1,y*2,z*3)
Upvotes: 6