Practice Question: Dict Keys
What is the output of the following code snippet?
a = (1,)
b = (2, [1, 2, 3])
d = {}
try:
d[a] = "f"
print(d[a], end="")
except Exception:
print("b", end="")
try:
d[b] = "g"
print(d[b], end="")
except Exception:
print("a", end="")Answer
The output is:
f,a # The tuple is not hashable; contains a list (mutable)