No changing the variable name wont do anything , it still points at the same objects
you need to use
you need to use
https://docs.python.org/3/library/copy.h...y.deepcopy Wrote:The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):
A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original.
A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.
import copy innerlist1 = [11111, 22222, 33333, 44444, 55555] innerlist2 = [0, 77777, 88888, 22222] innerlist3 = [22222, 11111, 33333, 44444] innerlist4 = [11111, 0], [55555, 88888] innerlist5 = [77777, 99999, 11111] innerlist6 = [22222, 55555, 33333, 99999] innerlist7 = [55555, 22222, 11111, 33333, 0, 44444, 77777] outerlist = [ innerlist1, innerlist2, innerlist3, innerlist4, innerlist5, innerlist6, innerlist7, ] outerlistcopy = copy.deepcopy(outerlist) print(outerlistcopy) innerlist1[0] = 99999 print(outerlistcopy) print(outerlist)
Output:[[11111, 22222, 33333, 44444, 55555], [0, 77777, 88888, 22222], [22222, 11111, 33333, 44444], ([11111, 0], [55555, 88888]), [77777, 99999, 11111], [22222, 55555, 33333, 99999], [55555, 22222, 11111, 33333, 0, 44444, 77777]]
[[11111, 22222, 33333, 44444, 55555], [0, 77777, 88888, 22222], [22222, 11111, 33333, 44444], ([11111, 0], [55555, 88888]), [77777, 99999, 11111], [22222, 55555, 33333, 99999], [55555, 22222, 11111, 33333, 0, 44444, 77777]]
[[99999, 22222, 33333, 44444, 55555], [0, 77777, 88888, 22222], [22222, 11111, 33333, 44444], ([11111, 0], [55555, 88888]), [77777, 99999, 11111], [22222, 55555, 33333, 99999], [55555, 22222, 11111, 33333, 0, 44444, 77777]]