C. · @cazabon
169 followers · 4177 posts · Server mindly.social

@matt

This does bite people in Python, as it applies to lists and dicts in addition to Pandas or whatever that is.

list and dict have copy() methods, but they're shallow copies. If you have mutable objects in your list or dict, those can be changed by someone with a copy...

Use copy.deepcopy() to ensure you get a mutable object that no one else (barring evil intent...) has a handle to fiddle with its contents.

#python #mutable #deepcopy

Last updated 1 year ago