PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#I don't know a good way to check whether an object is mutable or immutable, but I know that mutable objects will raise an error when included in as item in a set or as a key in a dictionary.
#I'm surprised OneUseObjects were immutable.
def is_mutable(x):
try:
{x}
except TypeError:
return True
else:
return False
class OneUseObject1: pass
class OneUseObject2:
def __init__(self):
self.var = 10
self.foo = []
#Sample dictionary for testing:
d = {
0: 4,
1: "47",
2: [4, 9],
3: (7, 1),
4: None,
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run