Is this PEP-able? fwhile

Fábio Santos fabiosantosart at gmail.com
Mon Jun 24 19:35:09 EDT 2013


On 25 Jun 2013 00:31, "alex23" <wuwei23 at gmail.com> wrote:
>
> On 25/06/2013 6:12 AM, Ian Kelly wrote:
>>
>> On Mon, Jun 24, 2013 at 1:52 PM,  <jimjhb at aol.com> wrote:
>>>
>>> Syntax:
>>> fwhile X in ListY and conditionZ:
>>>
>>> fwhile would act much like 'for', but would stop if the condition after
the
>>> 'and' is no longer True.
>>
>>
>> I would advocate using the break myself.  Another alternative is this:
>>
>> for X in itertools.takewhile(lambda X: conditionZ, ListY):
>>      ...
>
>
> I'd probably just go with a generator expression to feed the for loop:
>
>     for X in (i for i in ListY if conditionZ):
>         ....

That is nice but it's not lazy. If the condition or the iterables took too
long to compute, it would be troublesome.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130625/18ec013f/attachment.html>


More information about the Python-list mailing list