3 ms·
This is not a well written article. The Python documentation (https://docs.python.org/3/library/collections.html#collections.ChainMap https://docs.python.org/3
by ctur 5y ago
This is not a well written article. The Python documentation (https://docs.python.org/3/library/collections.html#collections.ChainMap https://docs.python.org/3/library/collections.html#collectio...) is clearer.
TLDR from the docs: ChainMap groups multiple dicts or other mappings together to create a single, updateable view.
- TameAntelope 5y ago> It is often much faster than creating a new dictionary and running multiple update() calls. This is the important detail. This is much faster than how you'd solve it pre-3.3. I found myself wondering why this required a new class in the stdlib until that line.
- amelius 5y agoIt would be nicer if Python just optimized the old way.
- laurencerowe 5y agoSemantically they’re not the same. In the ‘old way’ adding a key to one of the original dicts does not change the new dict. Whereas the new key will appear in the ChainMap.
- sixhobbits 5y agoThe author mentions right at the top of the blog that they are going through a tough time, and they put substantially more effort into this post than you did with your comment. > Be kind.