Nested List Comprehension
Greg Ewing
greg at cosc.canterbury.ac.nz
Tue Jul 17 22:55:30 EDT 2001
Burkhard Kroesen wrote:
>
> Maybe you feel more comfortable with
> multtab = [x*y for x in range(13) for y in range(13)]
But that doesn't produce what he wanted, which
was for multtab[x][y] to be equal to x*y.
But if there were such a thing as dictionary
comprehensions, he could use
multtab = {(x,y):x*y for x in range(13)
for y in range(13)}
:-)
--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list