[Python-bugs-list] Problem with multi-dimensional arrays (PR#94)

dcoffin@shore.net dcoffin@shore.net
Mon, 4 Oct 1999 16:35:05 -0400 (EDT)


Full_Name: Dave Coffin
Version: 1.5.2
OS: Linux
Submission from: (NULL) (206.166.179.42)


When I do an assignment of the form "array[i][j]=k", every element in
column j gets set to k:

Python 1.5.2 (#3, Sep 22 1999, 16:32:41)  [GCC egcs-2.91.66 19990314/Linux
(egcs- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> foo = [ [1] * 4 ] * 4
>>> foo
[[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
>>> foo[3]
[1, 1, 1, 1]
>>> foo[3][2]
1
>>> foo[3][2]=5
>>> foo
[[1, 1, 5, 1], [1, 1, 5, 1], [1, 1, 5, 1], [1, 1, 5, 1]]
>>> foo[1][2]
5