def dict_merge(a, b):
    """
    Merges two dictionaries, combining their keys/values at each level of nesting. If keys are duplicated between
    dictionaries, the values in the latter dictionary (b) will override those in the former (a).

    (This is different from a regular dict.update() in that it is recursive, rather than only looking at the top level.)
    """
    to_update = dict(a)

    for k, v in b.items():
        if isinstance(v, dict):
            to_update[k] = dict_merge(a.get(k, {}), v)
        else:
            to_update[k] = v

    return to_update