John Sahr added the comment:
I eventually figured that out that source of the problem;
thanks for the coding fix; that's useful to know.
-John
On Thu, Aug 11, 2016 at 8:17 AM, Emanuel Barry
wrote:
>
> Emanuel Barry added the comment:
>
> This is due to the fact that
New submission from John Sahr:
The following produces unexpected behavior.
I think that it should produce a list of six different lambda expressions,
but after creation, all six lambda expressions produce the same output.
It's possible that I'm missing something about Python.
# begin
Emanuel Barry added the comment:
This is due to the fact that Python evaluates the variable 'n' when the
function is called, not when it is created. As such, the variable holds the
latest value for all functions, and they exhibit identical behaviour.
Workaround:
...
f = lambda x, n=n: