On Fri, Dec 27, 2019, 12:05 PM Steven D'Aprano <st...@pearwood.info> wrote:
> On Fri, Dec 27, 2019 at 02:16:43PM +0000, Jonathan Fine wrote: > > Summary: dict.update(self, other) corresponds to 'merge-right'. Perhaps > add > > dict.gapfill(self, other), which corresponds to 'merge-left'. > I don't understand the connection between the name "gapfill" and any sort > of merge or update operation. To me, "filling a gap" means spraying > expanding foam into a hole, or using a spatula or similar tool to spread > filler into a hole. > Regardless of the function or method name potentially chosen, I definitely see the difference between: dict1.update(dict2) dict1.add_stuff_no_replace(dict2) I've been occasionally bitten by wanting the second rather than the first. So that's an argument in favor of adding something. Arguments against: 1. People should use collections.ChainMap more. Probably half the time anyone uses dict.update(), ChainMap would have been a better choice (in my code especially :-)) ChainMap(dict1, dict2) ChainMap(dict2, dict1) Those two have a perfectly clear distinction. Neither mutates the original dicts, and I could add dict3 to the places to look with no more lines of code. 2. The "left wins" semantics is less common and a function is perfectly adequate. Just write you're own dictutils.gapfill() and we're done. It's even worth having a module on PyPI if you can think of a half dozen more ways to useful combine dictionaries.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AUXDTOUQLBTGLLTZ3F67DE76VULXND72/ Code of Conduct: http://python.org/psf/codeofconduct/