On Mon, Mar 4, 2019, 11:45 AM Steven D'Aprano <st...@pearwood.info> wrote:

> > Like other folks in the thread, I also want to merge dicts three times
> per
> > year.
>
> I'm impressed that you have counted it with that level of accuracy. Is it
> on the same three days each year, or do they move about? *wink*
>

To be respectful, I always merge dicts on Eid al-Fitr, Diwali, and Lent. I
was speaking approximate since those do not appears line up with the same
Gregorian year.

> And every one of those times, itertools.ChainMap is the right way to do
> that non-destructively, and without copying.
>
> Can you elaborate on why ChainMap is the right way to merge multiple dicts
> into a single, new dict?
>

Zero-copy.


> ChainMap also seems to implement the opposite behaviour to that usually
> desired: first value seen wins, instead of last:
>

True, the semantics are different, but equivalent, to the proposed dict
addition. I put the key I want to "win" first rather than last.

If you know ahead of time which order you want, you can simply reverse it:
>

This seems nonsensical. If I write, at some future time,
'dict1+dict2+dict3' I need exactly as much to know "ahead of time" which
keys I intend to win.
_______________________________________________
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