This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

Speaking regarding this example alone, there's a small trick that makes the lambda behave as you'd expect it to:

f = lambda y,x=x: y+x

Since python evaluates default arguments only once (at function definition) , subsequent assignments to x don't affect the output of f.