[Python-ideas] Yield-from example: A parser

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Feb 18 20:38:39 CET 2009


Bruce Frederiksen wrote:

> I guess I'm not the only one who's intuitive feel for "for" loops is 
> that they run to exhaustion (and, yes, it feels right to use for loops 
> to search a list for something and break when it's found, but even then 
> it feels like the program should be done with the iterable when the for 
> loop terminates).

Yes, the early break from a searching loop is more of
an optimisation -- you *could* carry on and scan the
rest of the list, remembering what you found, but
there's no point in doing so.

It's different when the iterator has side effects,
though. My instincts tell me not to use a for-loop
then unless the iterator really is going to be
exhausted.

-- 
Greg




More information about the Python-ideas mailing list