[Python-Dev] listcomps vs. for loops
Aahz
aahz at pythoncraft.com
Mon Oct 20 13:52:30 EDT 2003
On Mon, Oct 20, 2003, Guido van Rossum wrote:
>Aahz:
>>
>> ?!?! When listcomps were introduced, you were strongly against any
>> changes that would make it difficult to switch back and forth between a
>> listcomp and its corresponding equivalent for loop.
>
> I don't recall what I said then. Did I say it was a feature that
>
> L = [x for x in R]
> print x
>
> would print the last item of R?
What I remember you saying was that it was an unfortunate but necessary
consequence so that it would work the same as
L = []
for x in R:
L.append(x)
print x
You didn't want to have different semantics for two such similar
constructs ("there's only one way"). You also didn't want to push a
stack frame for listcomps.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
More information about the Python-Dev
mailing list