Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95001
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:skip:c 10': 0.07; 'cc:addr:python-list': 0.09; '"["': 0.09; 'pavel': 0.09; 'wed,': 0.15; '"]"': 0.16; '"for"': 0.16; '"if"': 0.16; '"in"': 0.16; '::=': 0.16; '[","]]': 0.16; '[(","': 0.16; 'clauses': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ifs': 0.16; 'list_display': 0.16; 'list_for': 0.16; 'list_if': 0.16; 'list_iter': 0.16; 'or_test': 0.16; 'target_list': 0.16; 'wrote:': 0.16; 'alternate': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'seems': 0.23; 'header :In-Reply-To:1': 0.24; 'subject:list': 0.26; 'message- id:@mail.gmail.com': 0.27; 'skip:[ 10': 0.31; 'received:google.com': 0.35; "isn't": 0.35; 'but': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'subject:with': 0.40; 'different': 0.63; "'and'": 0.84; "'for'": 0.84; 'chrisa': 0.84; 'clauses,': 0.84; 'to:none': 0.91 |
| 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:cc :content-type; bh=lIiVsYIBYeQiJIymzf3Fx3cyRR6zvbgTRu7M3f8zhLA=; b=Wm3YEi/psP6gjQce6VHVOonxuX0pYZoPitVfUzrelaeeQWswauT2GOjiXsWeSZijn4 AB414VYs4UXdYVyqmItYHzGiylZ7LeLItlsOvIVlcFzGNo5N+xJ4XLkj1cIUNfJ63Lux CTutloAIn0MaRda6AwmQNceZvAqiIBdLHmR+rt9nBNzHqw2U74nqvj+VSuhdjA0+67d6 11oDjYVs5upaPOTRpsfT6ov0mhkLdTEE14MIQk4RJoXE2WAq8c4n1cPDconjksVMqFML wPNTGX0E6Bas23z2guXZQJmJ68L7Lsu8I5U3PfikTx+XETjFyrQ/Z13qKdO03f2eg8Af hR9A== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.60.68 with SMTP id f4mr9355947igr.94.1438759205584; Wed, 05 Aug 2015 00:20:05 -0700 (PDT) |
| In-Reply-To | <631b480d-497a-4451-9577-2788f9d4c85b@googlegroups.com> |
| References | <ebf0a31e-1021-41d2-affb-8318838a464b@googlegroups.com> <631b480d-497a-4451-9577-2788f9d4c85b@googlegroups.com> |
| Date | Wed, 5 Aug 2015 17:20:05 +1000 |
| Subject | Re: GOTCHA with list comprehension |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1232.1438759213.3674.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1438759213 news.xs4all.nl 2911 [2001:888:2000:d::a6]:37359 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Bytes | 4079 |
| X-Received-Body-CRC | 2497873584 |
| Xref | csiph.com comp.lang.python:95001 |
Show key headers only | View raw
On Wed, Aug 5, 2015 at 5:03 PM, Pavel S <pavel@schon.cz> wrote:
> It seems this is allowed by the grammar:
>
> list_display ::= "[" [expression_list | list_comprehension] "]"
> list_comprehension ::= expression list_for
> list_for ::= "for" target_list "in" old_expression_list [list_iter]
> old_expression_list ::= old_expression [("," old_expression)+ [","]]
> old_expression ::= or_test | old_lambda_expr
> list_iter ::= list_for | list_if
> list_if ::= "if" old_expression [list_iter]
>
> So chaining multiple ifs is fine:
>
> [ i for i in range(10) if True if True if True if True ]
Yep. A chain of 'if' clauses isn't materially different from a single
'if' with a bunch of 'and' checks, but if you alternate 'if' and 'for'
clauses, you get a comprehension that conditionally nests its
iterations.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
GOTCHA with list comprehension Pavel S <pavel@schon.cz> - 2015-08-04 23:48 -0700
Re: GOTCHA with list comprehension Pavel S <pavel@schon.cz> - 2015-08-05 00:03 -0700
Re: GOTCHA with list comprehension Chris Angelico <rosuav@gmail.com> - 2015-08-05 17:20 +1000
Re: GOTCHA with list comprehension Peter Otten <__peter__@web.de> - 2015-08-05 09:04 +0200
Re: GOTCHA with list comprehension Chris Angelico <rosuav@gmail.com> - 2015-08-05 17:05 +1000
Re: GOTCHA with list comprehension Pavel S <pavel@schon.cz> - 2015-08-05 00:10 -0700
Re: GOTCHA with list comprehension Chris Angelico <rosuav@gmail.com> - 2015-08-05 17:21 +1000
Re: GOTCHA with list comprehension Pavel S <pavel@schon.cz> - 2015-08-05 00:33 -0700
Re: GOTCHA with list comprehension Marko Rauhamaa <marko@pacujo.net> - 2015-08-05 12:01 +0300
Re: GOTCHA with list comprehension Chris Angelico <rosuav@gmail.com> - 2015-08-05 19:52 +1000
Re: GOTCHA with list comprehension Marko Rauhamaa <marko@pacujo.net> - 2015-08-05 14:10 +0300
Re: GOTCHA with list comprehension Saran Ahluwalia <ahlusar.ahluwalia@gmail.com> - 2015-08-07 09:08 -0400
Re: GOTCHA with list comprehension Laura Creighton <lac@openend.se> - 2015-08-06 06:39 +0200
Re: GOTCHA with list comprehension Chris Angelico <rosuav@gmail.com> - 2015-08-06 14:44 +1000
csiph-web