In message <[EMAIL PROTECTED]>, Duncan Booth wrote:

> We already get people asking why code like this doesn't return 3:
> 
>>>> fns = [ lambda: x for x in range(10) ]
>>>> fns[3]()
> 9
> 
> ... making this change to default arguments would mean the
> solution usually proposed to the function scoping question above would no
> longer work:
> 
>>>> fns = [ lambda y=x: y for x in range(10) ]
>>>> fns[3]()
> 3

The right solution, of course, is

    fns = [(lambda x : lambda : x)(x) for x in range(10)]

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to