Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54226
| X-Received | by 10.224.16.1 with SMTP id m1mr5557905qaa.8.1379339032571; Mon, 16 Sep 2013 06:43:52 -0700 (PDT) |
|---|---|
| X-Received | by 10.50.80.78 with SMTP id p14mr2136605igx.6.1379339032535; Mon, 16 Sep 2013 06:43:52 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!d5no143811qap.0!news-out.google.com!gv3ni309qab.0!nntp.google.com!d5no168517qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Mon, 16 Sep 2013 06:43:52 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=189.128.127.244; posting-account=EOl8IgoAAACyJhiCerI1hBqAj62mcnzC |
| NNTP-Posting-Host | 189.128.127.244 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <eae87c72-f62d-4815-bb69-ca862ff78f1e@googlegroups.com> (permalink) |
| Subject | How is this list comprehension evaluated? |
| From | Arturo B <a7xrturodev@gmail.com> |
| Injection-Date | Mon, 16 Sep 2013 13:43:52 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:54226 |
Show key headers only | View raw
Hello, I'm making Python mini-projects and now I'm making a Latin Square
(Latin Square: http://en.wikipedia.org/wiki/Latin_square)
So, I started watching example code and I found this question on Stackoverflow:
http://stackoverflow.com/questions/5313900/generating-cyclic-permutations-reduced-latin-squares-in-python
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:
[[a[0 - 0] for 0 in range(4)] for 0 in range(4)]
[[a[1 - 1] for 1 in range(4)] for 1 in range(4)]
[[a[2 - 2] for 2 in range(4)] for 2 in range(4)]
[[a[3 - 3] for 3 in range(4)] for 3 in range(4)]
But I think I'm wrong... So, could you explain me as above? It would help me a lot.
Thanks for reading!
Back to comp.lang.python | Previous | Next — 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