U
Uwe Schmitt
Hi,
I just tried (Python 2.3)
li = [ lambda x: x*a for a in range(10) ]
which results in
li[0](1) = 9
...
li[9](1) = 9
In order to achieve the intended result I had to fall back on the
following trick:
li = [ lambda x,a=a: x*a for a in range(10)]
which leads to the expected result.
Any explanations ???
Greetings, Uwe.
I just tried (Python 2.3)
li = [ lambda x: x*a for a in range(10) ]
which results in
li[0](1) = 9
...
li[9](1) = 9
In order to achieve the intended result I had to fall back on the
following trick:
li = [ lambda x,a=a: x*a for a in range(10)]
which leads to the expected result.
Any explanations ???
Greetings, Uwe.