Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54229
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <torriem+gmail@torriefamily.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'python,': 0.02; 'newbie': 0.05; '[1,': 0.09; 'subject:skip:c 10': 0.09; 'subject:How': 0.10; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; "i've": 0.25; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'subject:list': 0.30; "i'm": 0.30; 'figure': 0.32; 'convert': 0.35; 'subject:?': 0.36; 'list': 0.37; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'helps': 0.61; 'subject:this': 0.83; '"j"': 0.84; 'square,': 0.84 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| Date | Mon, 16 Sep 2013 08:20:44 -0600 |
| From | Michael Torrie <torriem@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: How is this list comprehension evaluated? |
| References | <eae87c72-f62d-4815-bb69-ca862ff78f1e@googlegroups.com> |
| In-Reply-To | <eae87c72-f62d-4815-bb69-ca862ff78f1e@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| 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.31.1379341258.18130.python-list@python.org> (permalink) |
| Lines | 25 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1379341258 news.xs4all.nl 15958 [2001:888:2000:d::a6]:44970 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:54229 |
Show key headers only | View raw
On 09/16/2013 07:43 AM, Arturo B wrote:
> It uses a list comprenhension to generate the Latin Square, I'm am a newbie to Python, and I've tried to figure out how this is evaluated:
>
> a = [1, 2, 3, 4]
> n = len(a)
> [[a[i - j] for i in range(n)] for j in range(n)]
>
> I don't understand how the "i" and the "j" changes.
> On my way of thought it is evaluated like this:
It helps to convert it to a conventional for loop to see how it works:
a = [1, 2, 3, 4]
n = len(a)
resultj = []
for j in range(n):
resulti = []
for i in range(n):
resulti.append(a[i-j])
resultj.append(resulti)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How is this list comprehension evaluated? Arturo B <a7xrturodev@gmail.com> - 2013-09-16 06:43 -0700 Re: How is this list comprehension evaluated? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-16 15:53 +0200 Re: How is this list comprehension evaluated? Michael Torrie <torriem@gmail.com> - 2013-09-16 08:20 -0600 Re: How is this list comprehension evaluated? Roy Smith <roy@panix.com> - 2013-09-16 20:04 -0400
csiph-web