Arrays? (Or lists if you prefer)

Andrea Griffini agriff at tin.it
Mon Oct 23 02:43:40 EDT 2006


Neil Cerutti wrote:

>     >>> b =[range(2), range(2)]

I often happened to use

       b = [[0] * N for i in xrange(N)]

an approach that can also scale up in dimensions;
for example for a cubic NxNxN matrix:

       b = [[[0] * N for i in xrange(N)]
            for j in xrange(N)]

Andrea



More information about the Python-list mailing list