[Python-Dev] RE: Iteration variables and list comprehensions (original) (raw)

David Beazley beazley@cs.uchicago.edu
Thu, 31 May 2001 08:34:57 -0500 (CDT)


Greg Ewing writes:

Another advantage of changing both together is that we can continue to describe listcomp semantics in terms of for-loops instead of lambdas.

Is this really an advantage? To me, the lambda semantics are a lot more intuitive in terms of matching the way that list comprehensions are actually used and ought to work (although I will agree that the for-loop explanation is a good way to describe the internals of what a list comprehension actually does).

I think I would be opposed to changing normal for-loop semantics to match any change made in list-comprehensions. There are too many cases where you use a loop variable after finishing a loop and I suspect that this would break a huge amount of code. For example:

for i in r:
    ...
    if whatever: break

print i

Besides, the semantic mismatch created between a listcomp and a for-loop pales in comparison to the mismatch that currently exists between the behavior of listcomps and all of the other operators. Of course, that's just my opinion--I could be wrong.

Then we won't have to go into hiding until Guido dies or lifts the fatwah against us.

fatwah? Uh... should I start talking to the witness protection program folks?

Cheers,

Dave