Python: How to copy a multidimensional list by value without nested cycles?

Viewed 24

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 dicts. So is there some compact way to copy such nested structures?

1 Answers
from copy import deepcopy

b = deepcopy(a)
Related