Practice Question: Dict Keys

What is the output of the following code snippet?

Python
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:

Python
f,a     # The tuple is not hashable; contains a list (mutable)
Back to collection