[Python-Dev] PEP 3142: Add a "while" clause to generator expressions
Gustavo Carneiro
gjcarneiro at gmail.com
Mon Jan 19 19:43:42 CET 2009
2009/1/19 Vitor Bosshard <algorias at yahoo.com>
>
>
>
>
> ----- Mensaje original ----
> > De: Gerald Britton <gerald.britton at gmail.com>
> > Para: Terry Reedy <tjreedy at udel.edu>
> > CC: python-dev at python.org
> > Enviado: lunes, 19 de enero, 2009 15:03:47
> > Asunto: Re: [Python-Dev] PEP 3142: Add a "while" clause to generator
> expressions
> >
> > Duly noted and thanks for the feedback! (just what I was looking for
> > actually). I do disagree with the idea that the proposal, if
> > implemented, would make Python harder to learn. Not sure who would
> > find it harder. Having to find and use takewhile was harder for me.
> > I still find that one counter-intuitive. I would have expected the
> > parameters in the reverse order (take something, while something else
> > is true). Tripped me up a few times, which got me thinking about an
> > alternative.
>
>
> Are you even sure the list comprehension doesn't already shortcut
> evaluation?
>
> This quick test in 2.6 hints otherwise:
>
>
> >>> a = (i for i in range(10) if i**2<10)
> >>> a.next()
> 0
> >>> a.next()
> 1
> >>> a.next()
> 2
> >>> a.next()
> 3
> >>> a.next()
> Traceback (most recent call last):
> File "<pyshell#32>", line 1, in <module>
> a.next()
> StopIteration
Does not prove anything.
---- test.py ----
source = iter(xrange(10))
a = (i for i in source if i**2<10)
print list(a)
print list(source)
---- output ---
$ python /tmp/test.py
[0, 1, 2, 3]
[]
While 'a' is being evaluated, the source iterator is first completely
exhausted. If the source iterator is infinite, an infinite loop is created
and the program doesn't terminate.
>
>
> ¡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 at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/gjcarneiro%40gmail.com
>
--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090119/69f56de8/attachment-0001.htm>
More information about the Python-Dev
mailing list