array of arrays question

Meo eric.paquet at isrec.ch
Tue Aug 30 10:57:49 CEST 2005


Hi,

Here is what I'm doing in python 2.4.1 :

>>> aOfa=[[[]]*3]*4
>>> aOfa
[[[], [], []], [[], [], []], [[], [], []], [[], [], []]]
>>> aOfa[3][2].append(1)
>>> aOfa
[[[1], [1], [1]], [[1], [1], [1]], [[1], [1], [1]], [[1], [1], [1]]]

Ok, so there is something I didn't understand about python's arrays.

The result I was expecting was :

[[[], [], []], [[], [], []], [[], [], []], [[], [], [1]]]

Somebody understand what's going on here?

Thank




More information about the Python-list mailing list