Lambda forms and scoping

Michele Simionato michele.simionato at gmail.com
Fri Mar 20 08:41:37 EDT 2009


On Mar 19, 10:52 pm, Márcio Faustino <m.faust... at gmail.com> wrote:
> Hi,
>
> Executing the example below doesn't produce the expected behavior, but
> using the commented code does. Is this normal, or is it a problem with
> Python?

It is a common gotcha. Notice that it has nothing to do with lambda
functions, you
would get the same issue with regular functions.

This post http://www.artima.com/forums/flat.jsp?forum=106&thread=251156
and especially the comments
below should share some light on why it is the way it is (short
answer: for loops are
implemented by mutating the loop variable at each iteration).



More information about the Python-list mailing list