Here is a working implementation of dictionary addition, for consideration with the PEP: https://bugs.python.org/issue36144 Brandt
On Feb 27, 2019, at 16:07, Guido van Rossum <guido@python.org> wrote:
OK, you're it. Please write a PEP for this.
On Wed, Feb 27, 2019 at 3:53 PM Steven D'Aprano <steve@pearwood.info> wrote: On Wed, Feb 27, 2019 at 10:34:43AM -0700, George Castillo wrote:
The key conundrum that needs to be solved is what to do for `d1 + d2` when there are overlapping keys. I propose to make d2 win in this case, which is what happens in `d1.update(d2)` anyways. If you want it the other way, simply write `d2 + d1`.
This would mean that addition, at least in this particular instance, is not a commutative operation. Are there other places in Python where this is the case?
Strings, bytes, lists, tuples.
In this case, I wouldn't call it dict addition, I would call it a union operator. That suggests that maybe we match sets and use | for union.
That also suggests d1 & d2 for the intersection between two dicts, but which value should win?
More useful than intersection is, I think, dict subtraction: d1 - d2 being a new dict with the keys/values from d1 which aren't in d2.
-- Steven _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido) _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/