On Wed, Jun 14, 2006 at 03:33:31PM +1000, Tim Leslie wrote:
[...]
> You can have generators which look like list comprehensions, but they
> still have the same problem of the if statement only acting as a
> filter, not a stopping condition. If you wanted it to work you'd have
> to shift your condition into a generator function which took your list
> and your condition, at which point it's way too bulky compared to the
> very original version.

Actually, you can stop generator comprehensions:

    class Stopper:
        def __nonzero__(self):
            raise StopIteration
    
    stop = Stopper()
    
    print list(x**2 for x in range(10) if x < 5 or stop)

-Andrew.


_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders

Reply via email to