multiple index inconsistency

bert kilaruba at copper.net
Wed Sep 18 16:59:58 EDT 2002


The following line of code
>>> a = 3*[range(3)]
produces
[[0, 1, 2], [0, 1, 2], [0, 1, 2]]

If I then write, say, 
>>> a[0][1] = 3.7
I get
[[0, 3.7, 2], [0, 3.7, 2], [0, 3.7, 2]]
and not
[[0, 3.7, 2], [0, 1, 2], [0, 1, 2]]

Now if I write
>>> a = [[0, 1, 2], [0, 1, 2], [0, 1, 2]]
instead, and then 
>>> a[0][1] = 3.7
I get the result I expected (and wanted):
[[0, 3.7, 2], [0, 1, 2], [0, 1, 2]]
Why the inconsistency? Is this a bug or am I missing something?
-- 
Bert



More information about the Python-list mailing list