For a more general solution that works regardless of the number of dimensions, use copy.deepcopy()
:
import copy
b = copy.deepcopy(a)
More Related Contents:
- How to deep copy a list?
- Does a slicing operation give me a deep or shallow copy?
- How do I clone a list so that it doesn’t change unexpectedly after assignment?
- What is the difference between shallow copy, deepcopy and normal assignment operation?
- What is the difference between `sorted(list)` vs `list.sort()`?
- How can I make a deepcopy of a function in Python?
- How to make a completely unshared copy of a complicated list? (Deep copy is not enough)
- Shuffling a list of objects
- Understanding dict.copy() – shallow or deep?
- How do I merge a list of dicts into a single dict?
- How to do a recursive sub-folder search and return files in a list?
- List of lists into numpy array
- Replace values in list using Python [duplicate]
- Is there a better way to iterate over two lists, getting one element from each list for each iteration? [duplicate]
- Python – How to check list monotonicity
- Why does appending to one list also append to all other lists in my list of lists? [duplicate]
- Using an index to get an item
- Some built-in to pad a list in python
- Remove duplicates and original from list
- Python – sum values in dictionary
- Convert list into a pandas dataframe
- Why do these list methods (append, sort, extend, remove, clear, reverse) return None rather than the resulting list?
- Appending to list in Python dictionary [duplicate]
- Does Python have an immutable list?
- Swap values in a tuple/list inside a list in python?
- Counting depth or the deepest level a nested list goes to
- Which is the most efficient way to iterate through a list in python?
- How does str.startswith really work?
- Best way to remove elements from a list
- All possible permutations of a set of lists in Python