[Python-ideas] Is this PEP-able? for X in ListY while conditionZ:

David Mertz mertz at gnosis.cx
Tue Jun 25 21:41:36 CEST 2013


> David Mertz writes:

>
>  >> attendees = {guest:guest.plus_N for guest in waiting_list while
>  >> not room_full()}
>  >>
>  >> This would actually produce the same result as:
>  >>
>  >> attendees = {guest:guest.plus_N for guest in waiting_list if not
>  >> room_full()}
>
> Not necessarily.  waiting_list might be an infinite iterator .
>

Sure.  Of course.

I posted a followup which observed that 'room_full()' doesn't in principle
have to become True and stay that way either.  I was just trying to make an
intuitive example where the two forms would turn out the same, but
obviously there are a number of cases where they might be different.... and
hence a motivation for what I think would be nice as an added syntax in
comprehensions.

Actually, your example is an even stronger case for why we might want a
comprehension while clause.

-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130625/a9780d97/attachment.html>


More information about the Python-ideas mailing list