import collections
If you are not using Python 2.7+, replace isinstance(v, collections.Mapping) with isinstance(v, dict) (for strict printing) or hasattr(v, "items") (for duck input).
Note that if there is a conflict for some key - that is, if d1 has a string value, and d2 has a dict value for this key - then this implementation simply saves the value from d2 (similar to update )
source share