Is this PEP-able? fwhile
alex23
wuwei23 at gmail.com
Mon Jun 24 19:14:44 EDT 2013
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):
....
More information about the Python-list
mailing list