'while' in list comprehension?

Francis Avila francisgavila at yahoo.com
Wed Oct 22 19:13:41 EDT 2003


"Batista, Facundo" <FBatista at uniFON.com.ar> wrote in message
news:mailman.35.1066859181.702.python-list at python.org...
>#- I guess I see nothing really wrong with it, although I thought list
>#- comprehensions were supposed to make the iteration
>#- transparent--'while'
>#- kinda destroys the illusion.  But these are the only two
>#- looping constructs
>#- that make sense in a list comprehension, so why not support
>#- both?  OTOH,
>#- 'while' makes no sense in a dictionary comprehension (and
>#- presumably we'll
>#- have those one day.)
>
>Anybody willing to make a PEP?
>
>:)
>
>. Facundo
>

You mean for dict comprehensions? www.python.org/peps/pep-0274.html
See also Guido's reaction (basically, "Python 3"):
http://www.python.org/doc/essays/pepparade.html
(Personally, I would absolutely love dict comprehensions: I find
manipulating dicts clumsy.)

If you mean adding 'while' to list comprehensions, if I knew anything about
CPython internals, I would probably write it myself (I can't imagine it
would be very difficult--famous last words).  But yes, I think it's a small
thing that should go into a PEP, even if only so that someone more
experienced could explain why it should be rejected.
--
Francis Avila





More information about the Python-list mailing list