[Python-ideas] dict.merge(d1, d2, ...) (Counter proposal for PEP 584)
Steven D'Aprano
steve at pearwood.info
Thu Mar 21 12:21:23 EDT 2019
On Thu, Mar 21, 2019 at 09:11:18AM -0700, Guido van Rossum wrote:
> I don't find it easy to understand or remember that d1.update(d2) modifies
> d1 in place, while d1.merge(d2) first copies d1.
>
> Maybe the name can indicate the copying stronger? Like we did with sorting:
> l.sort() sorts in-place, while sorted(l) returns a sorted copy.
How about dict.merged(*args, **kw)? Or dict.updated()?
That would eliminate some of the difficulties with an operator, such as
the difference between + which requires both operands to be a dict
but += which can take any mapping or (key,value) iterable.
--
Steven
More information about the Python-ideas
mailing list