[Python-ideas] Is this PEP-able? for X in ListY while conditionZ:
Shane Green
shane at umbrellacode.com
Tue Jun 25 21:50:57 CEST 2013
Create “stop” which is basically an alias for “break” but always used in the way that’s not considered bad practice.
[x for x in l if x < 100 else stop]
On Jun 25, 2013, at 12:22 PM, jimjhb at aol.com wrote:
>
>
>
> >-----Original Message-----
> >From: Stephen J. Turnbull <stephen at xemacs.org>
> >To: jimjhb <jimjhb at aol.com>
> >Cc: mertz <mertz at gnosis.cx>; python-ideas <python-ideas at python.org>
> >Sent: Tue, Jun 25, 2013 3:07 pm
> >Subject: Re: [Python-ideas] Is this PEP-able? for X in ListY while conditionZ:
>
> >jimjhb at aol.com writes:
>
> >> Main issue seems to be that programmers "shouldn't" shy away from
> >> 'break' (I can kind of see the argument both ways) but they do.
>
> >I guess I just hang around in the wrong company, because I don't see
> >it. Where can I find these programmers who shy away from these
> >constructs?
> Here:
> http://www.csee.umbc.edu/courses/201/spring13/standards.shtml
>
> >> I think for deserves a 'while' because it is really sparing in its
> >> implementation (no index, no explicit bounds check) and so deserves
> >> a clean way to prematurely terminate the loop if needed.
>
> >But this idea lacks coherence, in that 'break' statement syntax is far
> >more expressive than a 'while' clause in the 'for' statement can be.
> >The 'while' condition needs to satisfy expression syntax and be a
> >function of the loop variable.
> I didn't think the while had to be a function of the loop variable.
> end_condition = False
> for X in ListY while end_condition is False:
> >But 'break' can be used at the top of
> >the loop, bottom, or elsewhere while the new syntax can only implement
> >one of those. And the 'break' condition need not be a function of the
> >loop variable.
>
> >On the other hand, in list comprehensions and generator expressions,
> >the syntactic and functional restrictions on the condition need to be
> >satisfied anyway.
>
> By the way:
>
> > 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.
>
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130625/235f9170/attachment.html>
More information about the Python-ideas
mailing list