Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'syntax': 0.04; 'intermediate': 0.07; 'iterate': 0.09; 'shame': 0.09; 'useless': 0.09; 'cc:addr:python-list': 0.11; 'wrote': 0.14; '"for"': 0.16; '"if"': 0.16; '"in"': 0.16; 'discussion.': 0.16; 'elsewhere,': 0.16; 'expression,': 0.16; 'generator.': 0.16; 'hides': 0.16; 'loops': 0.16; 'simple.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'aug': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'exists': 0.24; 'filtering': 0.24; 'merge': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'waste': 0.30; 'message-id:@mail.gmail.com': 0.30; 'lines': 0.31; 'subject:end': 0.31; 'writes:': 0.31; 'there.': 0.32; 'regular': 0.32; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'sequence': 0.36; 'possible': 0.36; 'skip:& 10': 0.38; 'does': 0.39; 'even': 0.60; 'new': 0.61; 'spam.': 0.64; 'strategy': 0.64; 'sometimes.': 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=4pViffF0zMy7+PCpGU8bMbJcdE80MqEQOHEV6t3kjY0=; b=MKUp09LSG59O8P3sDz4+rwBOu0F0FHcp2lYiRTDMJ2RmKnVKTvzjririkJnqTyzamO VW/GZJDEoejpQkqKQGQLplR4+iTlZDOXY8sLoikI/xbgrPxTfi3p6PN6AUFbxDPsMoDh 59n4tnxp2b7pWNDNodnQjjmNlMS9z5crFmFUXdLhiCzZ2wPq9zgU6aK5OpR1p6kVYhC3 cU4nQrCfzfJUWfwAaIaDwNt5WndyunnBvStCS5A1l3CCXzeXvhNXOrGWPLOCzh6bhVHU uX/PzpP5fdaJGjtaKlVWumu7AqhSktlG9qCzEmEkJ7BrAOr0TnGY283AvuGfkxXARRs7 etXg== MIME-Version: 1.0 X-Received: by 10.224.12.146 with SMTP id x18mr908657qax.110.1377858737416; Fri, 30 Aug 2013 03:32:17 -0700 (PDT) In-Reply-To: <7wob8gywds.fsf@benfinney.id.au> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> Date: Fri, 30 Aug 2013 11:32:17 +0100 Subject: Re: semicolon at end of python's statements From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: Ben Finney Content-Type: multipart/alternative; boundary=089e0149d2cc984f5104e527bc65 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: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377858745 news.xs4all.nl 15921 [2001:888:2000:d::a6]:56575 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53287 --089e0149d2cc984f5104e527bc65 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 29 Aug 2013 23:20, "Ben Finney" wrote: > > F=E1bio Santos writes: > > > It is a shame that this is not possible in python. for..if exists in > > comprehensions and not in regular loops but that would be nice > > sometimes. > > So you use it in a generator expression, and iterate over the generator: > > for foo in (spam for spam in sequence if predicate(spam)): > process(spam) > > That way, there's no need for new syntax. The problem I have with that strategy is that it is repetitive and hinders readability. You wrote "for" and "in" twice, and spam (a pretty useless intermediate variable) thrice! While it does its job, it hides the true intent for filtering beneath a lot of (pun intended) spam. The "if" particle is nigh undetectable there. To get around this, I often declare a generator. But I still find it a bit awkward to have to look up the definition elsewhere, and to waste lines over something so simple. I can't say I understand why we don't merge the for loops' syntax with the comprehension syntax. Even after following the for..while discussion. --089e0149d2cc984f5104e527bc65 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On 29 Aug 2013 23:20, "Ben Finney" <ben+python@benfinney.id.au> wrote:
>
> F=E1bio Santos <fabiosa= ntosart@gmail.com> writes:
>
> > It is a shame that this is not possible in python. for..if exists= in
> > comprehensions and not in regular loops but that would be nice > > sometimes.
>
> So you use it in a generator expression, and iterate over the generato= r:
>
> =A0 =A0 for foo in (spam for spam in sequence if predicate(spam)):
> =A0 =A0 =A0 =A0 process(spam)
>
> That way, there's no need for new syntax.

The problem I have with that strategy is that it is repetiti= ve and hinders readability. You wrote "for" and "in" tw= ice, and spam (a pretty useless intermediate variable) thrice! While it doe= s its job, it hides the true intent for filtering beneath a lot of (pun int= ended) spam. The "if" particle is nigh undetectable there.

To get around this, I often declare a generator. But I still= find it a bit awkward to have to look up the definition elsewhere, and to = waste lines over something so simple.

I can't say I understand why we don't merge the for = loops' syntax with the comprehension syntax. Even after following the f= or..while discussion.

--089e0149d2cc984f5104e527bc65--