[Python-ideas] dict.merge(d1, d2, ...) (Counter proposal for PEP 584)

Nathaniel Smith njs at pobox.com
Tue Mar 5 03:49:48 EST 2019


On Mon, Mar 4, 2019 at 11:41 PM INADA Naoki <songofacandy at gmail.com> wrote:
> Then, I propose `dict.merge` method.  It is outer-place version
> of `dict.update`, but accepts multiple dicts.  (dict.update()
> can be updated to accept multiple dicts, but it's not out of scope).
>
> * d = d1.merge(d2)  # d = d1.copy(); d.update(d2)
> * d = d1.merge(d2, d3)  # d = d1.copy(); d.update(d2); d2.update(d3)
> * d = d1.merge(iter_of_pairs)
> * d = d1.merge(key=value)

Another similar option would be to extend the dict constructor to
allow: d = dict(d1, d2, d3, ...)

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the Python-ideas mailing list