[Python-ideas] adding dictionaries

Andrew Barnert abarnert at yahoo.com
Tue Jul 29 04:09:31 CEST 2014


On Jul 28, 2014, at 16:45, Alexander Heger <python at 2sn.net> wrote:

> The discussion seems to go such that because people can't agree
> whether the first or second occurrence of keys takes precedence, or
> what operator to use (already decided by the design of Counter) it is
> not done at all.  

Well, yeah, that happens a lot. An good idea that can't be turned into a concrete design that fits the language and makes everyone happy doesn't get added, unless it's so ridiculously compelling that nobody can imagine living without it.

But that's not necessarily a bad thing--it's why Python is a relatively small and highly consistent language, which I think is a big part of why Python is so readable and teachable.

Anyway, I think you're on to something with your idea of adding an updated or union or whatever function/method whose semantics are obvious, and then mapping the operators to that method and update. I can definitely buy that a.updated(b) or union(a, b) favors values from b for exactly the same reason a.update(b) does (although as I mentioned I have other problems with a union function).

Meanwhile, if you have use cases for which ChainMap is not appropriate, you might want to write a dict subclass that you can use in your code or in teaching students or whatever, so you can amass some concrete use cases and show how much cleaner it is than the existing alternatives.

> To be fair, I am not a core Python programmer and am
> asking others to implement this - or maybe even agree it would be
> useful -, maybe pushing too much where just an idea should be floated.

If it helps, if you can get everyone to agree on this, except that none of the core devs wants to do the work, I'll volunteer to write the C code (after I finish my io patch and my abc patch...), so you only have to add the test cases (which are easy Python code; the only hard part is deciding what to test) and the docs.


More information about the Python-ideas mailing list