unintuitive for-loop behavior

Rustom Mody rustompmody at gmail.com
Sat Oct 1 00:43:34 EDT 2016


On Saturday, October 1, 2016 at 8:55:19 AM UTC+5:30, Random832 wrote:
> On Fri, Sep 30, 2016, at 20:46, Gregory Ewing wrote:
> > What *is* necessary and sufficient is to make each iteration
> > of the for-loop create a new binding of the loop variable
> > (and not any other variable!).
> 
> I don't think that's true. I think this is logic that is excessively
> tied to the toy examples that are used to illustrate the problem.
> 
> You don't think it's common [at least, as far as defining a lambda
> inside a loop at all is common] to do something like this?
> 
> for a in collection:
>     b = some_calculation_of(a)
>     do_something_with(lambda: ... b ...)

Common? — Dunno
What I know — Yuck!

[Yeah… someone brought up on Lisp and APL and who finds C++ terrifying!]



More information about the Python-list mailing list