Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81376
| Path | csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'class,': 0.07; 'nested': 0.07; 'subject:two': 0.07; 'correct,': 0.09; 'cc:addr:python- list': 0.11; 'creates': 0.14; 'books': 0.15; '24,': 0.16; 'brackets': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'innermost': 0.16; 'ivan': 0.16; 'through,': 0.16; 'wrote:': 0.18; 'starts': 0.20; 'example': 0.22; 'cc:addr:python.org': 0.22; 'initial': 0.24; 'math': 0.24; 'mon,': 0.24; 'looks': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'class': 0.32; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'right?': 0.36; 'nov': 0.38; 'subject:needed': 0.38; 'subject:skip:C 10': 0.61; 'entire': 0.61; "you're": 0.61; 'back': 0.62; 'fact,': 0.69; 'analysis': 0.75; 'maths': 0.84; 'to:none': 0.92 |
| 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=QNZUBkjZEvfV4SVmQPMVzDwRERdGoSTdKj0AUGY8MXs=; b=GytAV1YtmKO09ZBK3v3zwnhZwcRGXbLFrzc5CFY3u/foBfIhFq5zgcqKFCQiirpnse q18DvYm9bhKfbJR1sIPERC8KnFhgh5MWKB76LvlU1I/daKzQr0sPykcS7x+7Y9YQ9f4F 7X4/SYhQovw6GksOmonj7vc/hveYubnxdzAT31Br2Z9m8pJb+uJCwjTLe9MgJbe2NI60 Guat6vg2rAIzV/7q2Tq4KeRxra0Y+9Q9SBJiTmSZG0AsGjU7vfd+MTBshW2hJT5o5MZq CKtCrNYaGgoQMl0G9t/5Cjof0Q2fzylp0oft7+f1WOJMC7kUfUqr5MldsZTEIX/uH/i1 Ba/Q== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.134.39 with SMTP id i39mr13741872iod.53.1416757336618; Sun, 23 Nov 2014 07:42:16 -0800 (PST) |
| In-Reply-To | <002501d00733$6995dce0$3cc196a0$@gmail.com> |
| References | <mailman.16184.1416754678.18130.python-list@python.org> <d1194d28-e9ed-4bd3-86e9-899e13a17097@googlegroups.com> <002501d00733$6995dce0$3cc196a0$@gmail.com> |
| Date | Mon, 24 Nov 2014 02:42:16 +1100 |
| Subject | Re: Comprehension with two variables - explanation needed |
| 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.15 |
| 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.16189.1416757339.18130.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1416757339 news.xs4all.nl 2902 [2001:888:2000:d::a6]:52547 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:81376 |
Show key headers only | View raw
On Mon, Nov 24, 2014 at 2:37 AM, Ivan Evstegneev <webmailgroups@gmail.com> wrote: > As I know from books and googling, the comps main idea looks approximately > like this: > > [target <--main loop<--nested loop/s (and maybe some conditions)] Am I > right? > > But your code looks somehow inverted to me o_0 > > Like: > > [[target with nested loop] <--- main loop with initial values for target] Your analysis is correct, and it's because of the bracketing. Just as you learned back in maths class (or math class, if you're that sort), you start from the innermost brackets and work your way out. In fact, the nested example starts with the main loop, and for each value it goes through, it creates the entire inner comprehension. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Comprehension with two variables - explanation needed "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-11-23 16:56 +0200
Re: Comprehension with two variables - explanation needed Rustom Mody <rustompmody@gmail.com> - 2014-11-23 07:09 -0800
RE: Comprehension with two variables - explanation needed "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-11-23 17:37 +0200
Re: Comprehension with two variables - explanation needed Chris Angelico <rosuav@gmail.com> - 2014-11-24 02:42 +1100
RE: Comprehension with two variables - explanation needed Skip Montanaro <skip.montanaro@gmail.com> - 2014-11-23 09:45 -0600
Re: Comprehension with two variables - explanation needed Roy Smith <roy@panix.com> - 2014-11-23 10:57 -0500
Re: Comprehension with two variables - explanation needed Rustom Mody <rustompmody@gmail.com> - 2014-11-23 08:45 -0800
Re: Comprehension with two variables - explanation needed Rustom Mody <rustompmody@gmail.com> - 2014-11-23 09:17 -0800
RE: Comprehension with two variables - explanation needed "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-11-23 19:27 +0200
Re: Comprehension with two variables - explanation needed Steven D'Aprano <steve@pearwood.info> - 2014-11-24 04:42 +0000
Re: Comprehension with two variables - explanation needed Chris Angelico <rosuav@gmail.com> - 2014-11-24 15:51 +1100
Re: Comprehension with two variables - explanation needed Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-25 09:20 +1100
Re: Comprehension with two variables - explanation needed Rustom Mody <rustompmody@gmail.com> - 2014-11-23 22:47 -0800
Re: Comprehension with two variables - explanation needed Dan Stromberg <drsalists@gmail.com> - 2014-11-24 16:42 -0800
Re: Comprehension with two variables - explanation needed Skip Montanaro <skip.montanaro@gmail.com> - 2014-11-23 10:45 -0600
Re: Comprehension with two variables - explanation needed Roy Smith <roy@panix.com> - 2014-11-23 12:08 -0500
Re: Comprehension with two variables - explanation needed Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2014-11-23 17:46 +0000
csiph-web