Hi,

DATA = [ [ 0 for i in range(ncolumns) ] for i in range(nrows) ]

Is one way.

DON'T do it like this:

row = [0] * ncolumns
data = [ row ] * nrows # WRONG!

Since after that, every row is the exact same object; if you set data[0][0]
= 1, the first element of _every_ row is 1.

But I guess you already found out about that :-)

That said, are you sure a list of lists is the best data structure for what
you're trying to do? I keep being surprised by Python code that uses other
data structures in clever ways; lists of lists seem to be pretty rare!

Remco Gerlich

On Dec 6, 2007 4:29 PM, Horacius ReX <[EMAIL PROTECTED]> wrote:

> in python, when I want to use arrays, I follow this way;
>
> DATA = [0] * nint
>
> and when I want to use I do;
>
> ....
>
> DATA[i] = ....
>
> do you know how to do similar but in two dimensions ?
>
> thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to