Generator expressions vs. comprehensions

Terry Reedy tjreedy at udel.edu
Tue May 25 13:19:50 EDT 2010


On 5/25/2010 1:09 PM, Terry Reedy wrote:
> On 5/25/2010 3:08 AM, Peter Otten wrote:
>> Michele Simionato wrote:
>
>> I think not turning the list-comp into syntactic sugar for
>> list(genexp) in
>> py3 is a missed opportunity.
>
> Implementing it that way was tried but was much slower than the current
> implementation. If one uses StopIteration as it is intended to be used
> (and is so documented), then, I believe, they are equivalent. There was
> a conscious decision to not slow comprehensions for the many to cater to
> the very few.

And those few can always write list(genexp) instead of [genexp] (or 
set...) when the minute difference actually matters.

> Terry Jan Reedy
>





More information about the Python-list mailing list