2d lists

Piet van Oostrum piet at cs.uu.nl
Wed Jun 2 07:52:59 EDT 2004


>>>>> xiaohua_sun at yahoo.com (SunX) (S) wrote:

S> What is the best way to assign a 2d lists?  Something like;
S> for i in range(10):
S>     for j in range(10):
S>         aList[i][j] = i*j

S> Thank you in advance.

Use list comprehension:
aList = [[i*j for j in range(10)] for i in range(10)]
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl



More information about the Python-list mailing list