python 2.3's lambda behaves old fashioned
Uwe Schmitt
uwe.schmitt at procoders.net
Thu Apr 29 10:35:04 EDT 2004
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.
--
Dr. rer. nat. Uwe Schmitt http://www.procoders.net
schmitt at procoders.net "A service to open source is a service to mankind."
More information about the Python-list
mailing list