[Python-ideas] Dict joining using + and +=

INADA Naoki songofacandy at gmail.com
Fri Mar 1 06:59:45 EST 2019


I dislike adding more operator overload to builtin types.

str is not commutative, but it satisfies a in (a+b), and b in (a+b).
There are no loss.

In case of dict + dict, it not only sum.  There may be loss value.

   {"a":1} + {"a":2} = ?

In case of a.update(b), it's clear that b wins.
In case of a + b, "which wins" or "exception raised on duplicated key?" is
unclear to me.

Regards,

On Thu, Feb 28, 2019 at 1:28 AM João Matos <jcrmatos at gmail.com> wrote:

> Hello,
>
> I would like to propose that instead of using this (applies to Py3.5 and
> upwards)
> dict_a = {**dict_a, **dict_b}
>
> we could use
> dict_a = dict_a + dict_b
>
> or even better
> dict_a += dict_b
>
>
> Best regards,
>
> João Matos
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
INADA Naoki  <songofacandy at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190301/57459a44/attachment-0001.html>


More information about the Python-ideas mailing list