free variables /cell objects question

Paul Rubin http
Tue Jan 23 11:32:11 EST 2007


"gangesmaster" <tomerfiliba at gmail.com> writes:
> so this is why [lambda: i for i in range(10)] will always return 9.
> imho that's a bug, not a feature.

Use [(lambda j: lambda: j)(i) for i in range(10)]
or the Python idiom [(lambda i=i: i) for i in range(10)]



More information about the Python-list mailing list