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 

    d3 = d1 | d2  # TypeError

Where the last value of any duplicate keys should win.


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
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to