----- Mensaje original ---- > De: "python-3...@udmvt.ru" <python-3...@udmvt.ru> > Para: Gerald Britton <gerald.brit...@gmail.com> > CC: python-dev@python.org > Enviado: martes, 20 de enero, 2009 11:18:24 > Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator > expressions > > May I suggest you this variant? > > def raiseStopIteration(): > raise StopIteration > > g = (n for n in range(100) if n*n < 50 or raiseStopIteration()) > > Well, there are more characters... > > But it is not using any syntax changes and does not require any approval > to be functional. Yet it is as fast as the proposed variant, does not require > modules and, I hope, will not confuse you or anyone else. >
This works as a generator, but not as a list comprehension. The exception is propagated instead of just cutting short the loop: >>> def r(): raise StopIteration >>> print [i for i in range(10) if i**2 < 50 or r()] Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> print [i for i in range(10) if i**2 < 50 or r()] File "<pyshell#1>", line 1, in r def r(): raise StopIteration StopIteration >>> Vitor ¡Todo sobre la Liga Mexicana de fútbol! Estadisticas, resultados, calendario, fotos y más:< http://espanol.sports.yahoo.com/ _______________________________________________ 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