On Mon, May 30, 2011 at 11:48 PM, harrismh777 <harrismh...@charter.net> wrote:
>>>> fs=[]
>>>> fs = [(lambda n: i + n) for i in range(10)]
>>>> [fs[i](1) for i in range(10)]
>
> [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]         <=== not good
>
>    ( that was a big surprise! . . . )
<snip>
>     lambda?  closure?  scope?   bug?
>
>     What is going on with the binding in the first construct... this seems
> to reduce the usefulness of lambda to a considerable extent?

http://stackoverflow.com/questions/233673/lexical-closures-in-python
(See 1st and 2nd answers)

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to