[Python-ideas] Re: Should for loops run in their own scope?

2021-09-12 Thread Christopher Barker
In the example at the top of the discuss thread >>> larr = [lambda: i for i in range(10)] >>> iarr = [l() for l in larr] >>> iarr [9, 9, 9, 9, 9, 9, 9, 9, 9, 9] a comprehension is used, which already (kinda) creates it's own scope. So that is really about lambda, not loops. Or at least, that

[Python-ideas] Re: Should for loops run in their own scope?

2021-09-12 Thread David Mertz, Ph.D.
Honestly, the construct of `lambda x=x: stuff(x)` in a loop or comprehension isn't that hard to learn. Yes, I've also forgotten it and tripped over that. But then, I've also banged my head on the wall when I use a language with block scope and forget that variables won't be available after the