This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author loewis
Recipients loewis, stesteve
Date 2008-06-10.04:57:08
SpamBayes Score 0.0932808
Marked as misclassified No
Message-id <1213073830.36.0.651592956873.issue3072@psf.upfronthosting.co.za>
In-reply-to
Content
This is not a bug. Please read about references in Python, and what this
means:



py> b=[0]
py> a=[b,b]
py> a[0] is a[1]
True
py> c=[[0],[0]]
py> c[0] is c[1]
False
py> c[0] == c[1]
True

In short, there is only a single list stored in the variable gridRow,
and the very same list is appended multiple times (not copies of the
list, but the very same object). There are then multiple ways to refer
to the list, such as g[0] or g[1].

To avoid sharing the list objects, either create new lists (i.e. nest
the first loop into the second one, and create a new gridRow on each
outer loop iteration), or create clones of the first list, e.g.

  grid.append(list(gridRow))
# or
  grid.append(gridRow[:])
History
Date User Action Args
2008-06-10 04:57:10loewissetspambayes_score: 0.0932808 -> 0.0932808
recipients: + loewis, stesteve
2008-06-10 04:57:10loewissetspambayes_score: 0.0932808 -> 0.0932808
messageid: <1213073830.36.0.651592956873.issue3072@psf.upfronthosting.co.za>
2008-06-10 04:57:09loewislinkissue3072 messages
2008-06-10 04:57:09loewiscreate