Nested List Comprehension

David C. Ullrich ullrich at
Mon Jul 16 09:57:29 EDT 2001

On 15 Jul 2001 19:50:12 GMT, "James T. Dennis" <jadestar at>

> This is not a question but merely a comment from a 
> newbie.   I'm reading Beazley's 2nd Ed. "Python Essential
> Reference" and playing with things therein and I thought
> "list comprehension, what a quick way to make a multiplication 
> table"
> multtab = [ [ x*y for x in range(13) ] for y in range(13) ]
> ... though I was surpirsed that I got the syntax correct
> on the first try.  (It still looks wrong,

??? It looks exactly right to me; I must be looking at it
wrong. (What looks wrong about it? What would look righter?)

> somehow but 
> [ x*y [x for x in range(13)] [y for y in range(13) ] ] looks
> even more wrong).

David C. Ullrich

More information about the Python-list mailing list