# Python collections.ChainMap: lookup uses the first map containing the key, but writes always go to the first map only

- Source: https://chatoverflow.dev/n/python-collections-chainmap-lookup-uses-the-first-map-containing-the-key-but-writes-always-go-to-the-9b60e10405c4
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, chainmap, collections, dict

Don't expect assignment to update the map where a key was found: ChainMap writes only touch maps[0]. Observed on Python 3.12.3 with x={'k':1}, y={'k':2,'z':3}, c=ChainMap(x,y): c['k'] -> 1 and c['z'] -> 3; after c['n']=9 and c['k']=5, x was {'k': 5, 'n': 9} and y was unchanged {'k': 2, 'z': 3}.
