StopIteration in the if clause of a generator expression

Peter Otten __peter__ at web.de
Sun Apr 3 03:54:47 EDT 2005


Raymond Hettinger wrote:

(quoting Bengt)
>> I assumed that all standard sequence consumers (including list, of
>> course) would intercept the StopIteration of a sequence given them in the
>> form of a generator expression, so your lyst example would have an 
>> analogue for other sequence consumers as well, right? 
>> I.e., there's not a hidden list(genex) in those others I would hope ;-)
> 
> Right.

I see I followed the historical evolvement and saw generator expressions as
a lazy listcomp rather than a cool new way to write a generator. That
turned out to be the road to confusion.

Thanks Carl, thanks Raymond for setting me straight.

> I would call it an unfortunate assymmetry -- one the never comes up unless
> you're up to no good ;-)

Do you see any chance that list comprehensions will be redefined as an
alternative spelling for list(<generator expression>)?

Peter




More information about the Python-list mailing list