mindly.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mindly.Social is an English speaking, friendly Mastodon instance created for people who want to use their brains and their hearts to make social networking more social. 🧠💖

Administered by:

Server stats:

1.1K
active users

@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.

C.

@matt

Oh, and sets too.

Example with shallow list copy and an embedded mutable object (another list):

>>> a = [1, 2, [3, 4]]
>>> b = a.copy()

>>> b
[1, 2, [3, 4]]
>>> b[0] = 5
>>> b
[5, 2, [3, 4]]

>>> a
[1, 2, [3, 4]]

>>> b[2][0] = 8
>>> a
[1, 2, [8, 4]]
>>> b
[5, 2, [8, 4]]