On 1/20/2009 4:45 PM, Gerald Britton wrote:
OK, so your suggestion:

 g = (n for n in range(100) if n*n < 50 or raiseStopIteration())

really means "return in in the range 0-99 if n-squared is less than 50
or the function raiseStopIteration() returns True".

How would this get the generator to stop once n*n >=50? It looks
instead like the first time around, StopIteration will be raised and
(presumably) the generator will terminate.


I still find it odd to invent new syntax for simple things like


def quit(): raise StopIteration

gen = itertools.imap( lambda x: x if x <= 50 else quit(),
                      (i for i in range(100)) )

for i in gen: print i




Sturla Molden


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to