[Python-ideas] adding dictionaries

Alexander Heger python at 2sn.net
Tue Jul 29 00:21:09 CEST 2014


> When the underlying dicts and desired combined dict are all going to be used immutably, ChainMap is the perfect answer. (Better than an "updated" function for performance if nothing else.) And usually, when you're looking for a non-mutating combine-dicts operation, that will be what you want.
>
> But usually isn't always. If you want a snapshot of the combination of mutable dicts, ChainMap is wrong. If you want to be able to mutate the result, ChainMap is wrong.
>
> All that being said, I'm not sure these use cases are sufficiently common to warrant adding an operator--especially since there are other just-as-(un)common use cases it wouldn't solve. (For example, what I often want is a mutable "overlay" ChainMap, which doesn't need to copy the entire potentially-gigantic source dicts. I wouldn't expect an operator for that, even though I need it far more often than I need a mutable snapshot copy.)
>
> And of course, as you say, real-life use cases would be a lot more compelling than theoretical/abstract ones.

For many applications you may not care one way or the other, only for
some you do, and only then you need to know the details of operation.

My point is to make the dict() data structure more easy to use for
most users and use cases.  Especially novices.
This is what adds power to the language.  Not that you can do things
(Turing machines can) but that you can do them easily and naturally.


More information about the Python-ideas mailing list