While we're on the subject, I've tried to add dicts a few times over the years to get a new one but it doesn't work:

    d3 = d1 + d2  # TypeError

Thinking a bit, set union is probably a better analogue, but it doesn't work 
either:

    d3 = d1 | d2  # TypeError

Where the last value of any duplicate keys should win.

-Mike



On 2018-04-12 06:46, Andrés Delfino wrote:
Extending the original idea, IMHO it would make sense for the dict constructor to create a new dictionary not only from several mappings, but mixing mappings and iterables too.

Consider this example:

x = [(1, 'one')]
y = {2: 'two'}

Now: {**dict(x), **y}
Proposed: dict(x, y)
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to