candide wrote:

So what is the right way to initialize to 0 a 2D array ? Is that way
correct :


 >>> t=[[0 for _ in range(2)] for _ in range(3)]

That's overkill :) You can skip the inner loop by using a list display, eg

t=[[0,0] for _ in range(3)]


It seems there is no more trouble now :

 >>> t
[[0, 0], [0, 0], [0, 0]]
 >>> t[0][0]=1
 >>> t
[[1, 0], [0, 0], [0, 0]]
 >>>

Correct ?


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to