On Tue, Mar 5, 2019 at 5:50 PM Nathaniel Smith <[email protected]> wrote:
>
> On Mon, Mar 4, 2019 at 11:41 PM INADA Naoki <[email protected]> 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

Yes, it's an option too.

One obvious merit of d.merge(...) is it returns same type of d.
`type(d1)(d1, d2)` looks ugly.

But people just want dict instead of some subtype of dict.
This merit is not so important.

I'm bit nervous about adding much overload to constructor.
That's main reason why I proposed method instead of constructor.

Regards,
-- 
INADA Naoki  <[email protected]>
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to