[Python-ideas] Accepting multiple mappings as positional arguments to create dicts
Mike Miller
python-ideas at mgmiller.net
Thu Apr 12 15:15:56 EDT 2018
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)
More information about the Python-ideas
mailing list