[Tutor] modifying lists of lists

Ed Owens eowens0124 at gmx.com
Thu Oct 4 05:52:54 CEST 2012


You are fundamentally correct about my confusion, though I'm trying to work
with tuples as the lowest level, which may not be relevant here.


-----Original Message-----
.

py> H = [[1, 2]]
py> J = [H[0]]
py> print H
[[1, 2]]
py> print J
[[1, 2]]
py> H[0][0] = 99
py> print H  # expected, and got, [[99, 2]]
[[99, 2]]
py> print J  # expected [[1, 2]]
[[99, 2]]

--------------

Using your example:

Py> Import copy
py> H = [[1, 2]]
py> J = [H[0]]
py> print H
[[1, 2]]
py> print J
[[1, 2]]
py> H[0][1] = copy.deepcopy(H[0][0])
py> print H  # expected, and got, [[1,1]]
[[1,1]]
py> print J  # expected [[1,2]]  
[[1, 1]]

How do I decouple these references?



More information about the Tutor mailing list