Skip to content

Instantly share code, notes, and snippets.

View smithtrevor's full-sized avatar

Trevor Smith smithtrevor

View GitHub Profile
@smithtrevor
smithtrevor / dict_merge.py
Last active April 4, 2018 21:09 — forked from angstwad/dict_merge.py
Recursive dictionary merge in Python without modifying original also Python 3
import collections
def dict_merge(orig, changes):
""" Recursive dict merge. Inspired by :meth:``dict.update()``, instead of
updating only top-level keys, dict_merge recurses down into dicts nested
to an arbitrary depth, updating keys. The ``changes`` is merged with
``orig`` and returned as ``dct``
:param orig: dict onto which the merge is executed
:param changes: dct merged into dct
:return: dict