I have a multidimensional list with lots of data and I need to copy it to another variable.
Both
b = a.copy()
and
b = a[:][:][:][:]
don't help - I still have data in b
bound to data in a
Of course, I can copy it element by element with nested cycles (maybe only saving one level with .copy()
). But is there a better way?
PS: The situation gets even worse if my data are in dict
of lists
or dict
of dict
s. So is there some compact way to copy such nested structures?
CodePudding user response:
from copy import deepcopy
b = deepcopy(a)