... }
>>>
>>> o = d1.copy()
>>> o.update(d2)
>>> o
{'publisher': 'Academic Press',
'title': 'Structured Programming',
'locations': {'North America': 'New York', 'Europe': 'London'},
'authors': 'Dahl, Dijkstra, and Hoare'}
>>>
>>> merge(d1, d2)
{'publisher': 'Academic Press',
'title': 'Structured Programming',
'locations': {'Dijkstra': 'University of Texas',
'Hoare': 'Oxford University',
'Dahl': 'University of Oslo'},
'authors': 'Dahl, Dijkstra, and Hoare'}
>>>
>>> recursive_merge(d1, d2)
{'publisher': 'Academic Press',
'title': 'Structured Programming',
'locations': {'North America': 'New York',
'Europe': 'London',
'Dijkstra': 'University of Texas',
'Hoare': 'Oxford University',
'Dahl': 'University of Oslo'},
'authors': 'Dahl, Dijkstra, and Hoare'}
>>>
IMO, having more than one obvious outcome means that we should refuse
the temptation to guess. If we do, then the result is only obvious
to a subset of users and will be a surprise to the others.
It's also useful to note that I am having trouble coming up with
another programming language that supports a "+" operator for map types.
Does anyone have an example of another programming language that
allows for addition of dictionaries/mappings?
If so, what is the behavior there?
- dave
--
Any linter or project that treats PEP 8 as mandatory has *already*
failed, as PEP 8 itself states that the rules can be broken as needed. - Paul Moore.