2

I was trying to declare multidimensional array in python (array[3][3]) and I did it wrong way like this :

>>> a = [[None] * 3] * 3
>>> a
[[None, None, None], [None, None, None], [None, None, None]]
>>> a[0][0] = 1
>>> a
[[1, None, None], [1, None, None], [1, None, None]]

I understand that the first array is not duplicated but referenced three times but I don't understand why.

Can someone explains to me how python understand this declaration ?

Julien hadim
  • 101
  • 2
  • 1
    dupe of http://stackoverflow.com/questions/240178/python-list-of-lists-changes-reflected-across-sublists-unexpectedly – pvg Dec 20 '15 at 19:53

0 Answers0