I understand that, due to the way Python works x = []; y = x; x.append(1); y will print [1]. However, the reverse, say,
x = []; y = x; x.append(1); y
[1]
z = [1,2] temp
Why not make temp a copy of z:
temp
z
>>> z = [1, 2] >>> temp = z[:] >>> temp[1] = 3 >>> z [1, 2] >>> temp [1, 3] >>>
[:] easily makes a shallow copy of a list.
[:]
However, you might also be interested in copy.copy and copy.deepcopy, both of which come from Python's copy module.