List comprehension + lambdas - strange behaviour
Benjamin Peterson
benjamin at python.org
Thu May 6 16:29:34 EDT 2010
Artur Siekielski <artur.siekielski <at> gmail.com> writes:
>
> Of course I was expecting the list [0, 1, 2, 3, 4] as the result. The
> 'x' was bound to the final value of 'range(5)' expression for ALL
> defined functions. Can you explain this? Is this only counterintuitive
> example or an error in CPython?
The former. Closures are rebound in a loop.
More information about the Python-list
mailing list