<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 4, 2019, 11:45 AM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> Like other folks in the thread, I also want to merge dicts three times per<br>
> year. <br>
<br>
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*<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">To be respectful, I always merge dicts on <font color="#3c4043" face="roboto, helveticaneue, arial, sans-serif"><span style="max-height:999999px;background-color:rgb(255,255,255)">Eid</span></font> al-Fitr, Diwali, and Lent. I was speaking approximate since those do not appears line up with the same Gregorian year.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> And every one of those times, itertools.ChainMap is the right way to do that non-destructively, and without copying.<br>
<br>
Can you elaborate on why ChainMap is the right way to merge multiple dicts into a single, new dict?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Zero-copy.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
ChainMap also seems to implement the opposite behaviour to that usually desired: first value seen wins, instead of last:<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">True, the semantics are different, but equivalent, to the proposed dict addition. I put the key I want to "win" first rather than last.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If you know ahead of time which order you want, you can simply reverse it:<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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.</div></div>