Something is rotten in Denmark...
Chris Rebert
clp2 at rebertia.com
Tue May 31 03:00:04 EDT 2011
On Mon, May 30, 2011 at 11:48 PM, harrismh777 <harrismh777 at 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
More information about the Python-list
mailing list