Lambda evaluation

Eric Nieuwland eric.nieuwland at xs4all.nl
Fri Oct 7 10:10:54 EDT 2005


Joshua Ginsberg wrote:
> Try this one:
>
>>>> d = {}
>>>> for x in [1,2,3]:
> ...     d[x] = lambda *args: args[0]*x
> ...
>>>> d[1](3)

try it with:
	d[x] = (lambda x=x: (lambda *args: args[0]*x))()

the outer lambda fixes the value of x and produces the inner lambda 
with the fixed x value

--eric




More information about the Python-list mailing list