How to properly copy a list of dictionaries in python?

I think it has to do with deep vs shallow copying. I only know this because I ran into a very similar situation earlier this year.

When you say list2 = list1, list2 is a reference to list1, so any changes you make to list1 will also modify list2.

import copy
list2 = copy.deepcopy(list1)

Try this out.

2 Likes