Menu Close

How to copy a nested lists in Python?

Sometimes, we want to copy a nested lists in Python.

In this article, we’ll look at how to copy a nested lists in Python.

How to copy a nested lists in Python?

To copy a nested lists in Python, we can use the copy.deepcopy method.

For instance, we write

import copy

b = copy.deepcopy(a)

to copy the nested list a with copy.deepcopy and assign the copied list to b.

Conclusion

To copy a nested lists in Python, we can use the copy.deepcopy method.

Posted in Python, Python Answers