dict.fromkeys: Why a mutable default value gets shared

Create a Python dict with keys a/b/c and values 0:

d = dict.fromkeys('abc', 0)

But don’t do this, since the value will be shared and mutable:

d = dict.fromkeys('abc', [])
d['a'].append('x')
d['b'].append('y')
print(d)

{‘a’: [‘x’, ‘y’], ‘b’: [‘x’, ‘y’], ‘c’: [‘x’, ‘y’]} 🤯