Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 6
    But one should be cautious while using ChainMap there's a catch that if you have duplicate keys the values from first mapping get used and when you call a del on say a ChainMap c will delete the first mapping of that key.
    – Slayer
    Commented Feb 14, 2017 at 5:14
  • 13
    @Prerit What else would you expect it to do? That's the normal way chained namespaces work. Consider how $PATH works in bash. Deleting an executable on the path doesn't preclude another executable with the same name further upstream. Commented Feb 15, 2017 at 7:24
  • 4
    @Raymond Hettinger I agree, just added a caution. Most people may not know about it. :D
    – Slayer
    Commented Feb 15, 2017 at 15:15
  • @Prerit You could cast to dict to avoid that, i.e.: dict(ChainMap({}, y, x))
    – wjandrea
    Commented Jul 15, 2019 at 16:30
  • @RaymondHettinger We all know you designed ChainMap in the most reasonable way, thank you for it! Commented May 29, 2022 at 18:16