Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.057 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'advocate': 0.07; 'subject:PEP': 0.07; 'cc:addr:python-list': 0.11; '>>': 0.16; "'for',": 0.16; '24,': 0.16; 'iterables': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; '>>>': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'probably': 0.32; 'another': 0.32; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'too': 0.37; 'skip:& 10': 0.38; 'feed': 0.38; 'pm,': 0.38; 'expression': 0.60; 'ian': 0.60; 'subject:? ': 0.60; 'break': 0.61; 'took': 0.61; 'act': 0.63; 'to:addr:gmail.com': 0.65; 'subject:this': 0.83; "'and'": 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=PSSeNFoiuBRH2lrIi/5IcsSLVGBQbG3/KUHV1cs9QEY=; b=F4InOyJSHe/0mlgKIClfBOXDLYqQTsH11JET1jzsCZKOn92WUs4tf1SWIVJcIaU5YR K9Kq8DwF/4JkfieTg+K/nKTV49HztqRiXjEMR+XWUdyxflRpvn9zfBda91Vl3qWw+wi7 5boBknym/tnvBLsfaXONeyHy+gq4XIr6B5J0LjNEcVzilkPvhazxNYzYRZebpa5UPTkG V2SYMgpbFXfzuTlltcaU4/xObIImBSKGikQrtc91P0JZTX6OWQvv5P9IqWd7DaKvbxXy alB5BGD+P21qF3ihSZRUXQp62NzkAioANai5Gku23Hgm133q06WlioUJaqIAToa2ygvc cdhQ== MIME-Version: 1.0 X-Received: by 10.224.123.68 with SMTP id o4mr20740432qar.106.1372116909178; Mon, 24 Jun 2013 16:35:09 -0700 (PDT) In-Reply-To: References: <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> Date: Tue, 25 Jun 2013 00:35:09 +0100 Subject: Re: Is this PEP-able? fwhile From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: alex23 Content-Type: multipart/alternative; boundary=047d7bd6bc92f6461e04dfeedc8a Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372116912 news.xs4all.nl 15886 [2001:888:2000:d::a6]:48528 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49109 --047d7bd6bc92f6461e04dfeedc8a Content-Type: text/plain; charset=ISO-8859-1 On 25 Jun 2013 00:31, "alex23" wrote: > > On 25/06/2013 6:12 AM, Ian Kelly wrote: >> >> On Mon, Jun 24, 2013 at 1:52 PM, 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. --047d7bd6bc92f6461e04dfeedc8a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


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

That is nice but it's not lazy. If the condition or the = iterables took too long to compute, it would be troublesome.

--047d7bd6bc92f6461e04dfeedc8a--