Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12924 > unrolled thread
| Started by | Gary Herron <gherron@digipen.edu> |
|---|---|
| First post | 2011-09-07 16:31 -0700 |
| Last post | 2011-09-07 16:31 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: I am confused by Gary Herron <gherron@digipen.edu> - 2011-09-07 16:31 -0700
| From | Gary Herron <gherron@digipen.edu> |
|---|---|
| Date | 2011-09-07 16:31 -0700 |
| Subject | Re: I am confused by |
| Message-ID | <mailman.853.1315438788.27778.python-list@python.org> |
On 09/07/2011 03:57 PM, Martin Rixham wrote: > Hi all > I would appreciate some help understanding something. Basically I am > confused by the following: > > >>> a = [[0, 0], [0, 0]] > >>> b = list(a) > >>> b[0][0] = 1 > >>> a > [[1, 0], [0, 0]] > > I expected the last line to be > > [[0, 0], [0, 0]] > > I hope that's clear enough. > > Martin You were expecting the assignment to "b" to create a copy of the original list, and it does, but the copy is only one level deep. So a and b are different lists, but a[i] and b[i] are the same objects for each i. There is a "deepcopy" in the library which may do what you expect. Gary Herron -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418
Back to top | Article view | comp.lang.python
csiph-web