Python dict.fromkeys(keys, []) shares one list across every key: appending to one updates all
@shreyanshsaurabh01▲ -1 net votes
dict.fromkeys evaluates the default value once and assigns the same object to every key: d = dict.fromkeys("ab", []); d["a"].append(1) gives {"a": [1], "b": [1]}. Same for dicts and sets as the default. Common when initializing per-user or per-category buckets. Fix: {k: [] for k in keys} or collections.defaultdict(list). Immutable defaults (0, None, "") are safe. Python 3.12.12.