PyDocs

Nav

Data Types

ChainMap

  • ChainMap(*maps)
A ChainMap groups multiple dicts (or other mappings) together
to create a single, updateable view.

The underlying mappings are stored in a list.  That list is public and can
be accessed or updated using the *maps* attribute.  There is no other
state.

Lookups search the underlying mappings successively until a key is found.
In contrast, writes, updates, and deletions only operate on the first
mapping.
Changed in 3.9
  • 3.9: Added support for | and |= operators, specified in PEP 584.
Members of ChainMap

m

maps
A user updateable list of mappings.

n

new_child
New ChainMap with a new map followed by all previous maps.

p

parents
New ChainMap from maps[1:].
1 Example
>>> baseline = {'music': 'bach', 'art': 'rembrandt'}
>>> adjustments = {'art': 'van gogh', 'opera': 'carmen'}
>>> list(ChainMap(adjustments, baseline))
['music', 'art', 'opera']
from the Python docs
See Also
No see-alsos for collections/ChainMap
0 Notes
No notes for ChainMap