4 ms·
I see the example use case is exactly the same as the one given in the python documentation [1]. Any other practical use cases? [1] https://docs.python.org/3.7
by dangom 8y ago
I see the example use case is exactly the same as the one given in the python documentation [1]. Any other practical use cases?
[1] https://docs.python.org/3.7/library/collections.html#collections.ChainMap https://docs.python.org/3.7/library/collections.html#collect...
- mjw1007 8y agoIf you're implementing some kind of style sheet system, you often want to support a tower of overrides (say, theme → document → chapter → explicitly-marked-section).
- thedirt0115 8y agoIt's nice for anything with nested scopes -- Example that came to mind since a link to Crafting Interpreters was also on the front page: Variable lookup for for an interpreter. If each scope gets its own set of bindings, you can make a ChainMap from most specific to least specific and look up values from that instead of manually traversing scopes.