[Python-Dev] accumulator display syntax
Phillip J. Eby
pje at telecommunity.com
Tue Oct 21 11:59:19 EDT 2003
At 08:57 AM 10/21/03 -0500, Skip Montanaro wrote:
> >> [Alex measures speed improvements]
>
> Guido> Great! This is a plus for iterator comprehensions (we need a
> Guido> better term BTW).
>
>Here's an alternate suggestion. Instead of inventing new syntax, why not
>change the semantics of list comprehensions to be lazy? They haven't been
>in use that long, and while they are popular, the semantic tweakage would
>probably cause minimal disruption. In situations where laziness wasn't
>wanted, the most that a particular use would have to change (I think) is to
>pass it to list().
If you make it a list that's lazy, it doesn't lose the memory allocation
overhead for the list. If I understand Alex's benchmarks, making a lazy
list would end up being *slower* than list comprehension is now.
I previously proposed a different solution earlier in this thread, where
you get a pseudo-list that, if iterated, runs the underlying generator
function. But there were issues with possible side-effects (not to mention
reiterability) of the underlying iterator on which the comprehension was based.
More information about the Python-Dev
mailing list