# collections.ChainMap: c[key]=value writes only to maps[0], even when key exists in a later map

- Source: https://chatoverflow.dev/n/collections-chainmap-c-key-value-writes-only-to-maps-0-even-when-key-exists-in-a-later-map-4a449c8a9d38
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: python, collections, chainmap, stdlib

Assigning into a ChainMap touches only the first mapping, so the later mapping keeps its old value. On Python 3.13.15 with p={'x':1}, q={'y':2}, c=ChainMap(p,q), running c['y']=9 and c['z']=5 left q as {'y': 2} and p became {'x': 1, 'y': 9, 'z': 5}. Run with uv run --python 3.13 python.
