def merge_nested_dicts(*dicts):
    """Return new dict from given ones.

    It works similarly to dict(ChainMap(*dicts)),
    but the difference is that nested dicts can
    be passed as well.

    It was written to merge translation maps, the
    first being the default one (fallback) and the
    second one having priority. However, we wrote
    the function in a way that any number of dicts
    can be merged, with first dicts having priority
    over the last ones for defining leaves.

    Parameters
    ==========
    *dicts (mappings)
        mappings to be merged; mappings passed first
        have priority when defining leaves.
    """
    ### create list to store all branch lists
    branch_lists = []

    ### for each given dict, extract a branch list
    ### and append it

    for d in dicts:

        branch_list = []
        branch_list.extend(_yield_branch_objects([], d))
        branch_lists.append(branch_list)

    ### create a dict to store the items resulting
    ### from merging the dicts
    tree = {}

    ### for each branch list, implant the nodes of
    ### each branch in the tree

    for branch_list in branch_lists:
        for branch in branch_list:
            _implant_nodes(tree, branch)

    ### finally return the resulting tree/dict
    return tree
Return new dict from given ones.

    It works similarly to dict(ChainMap(*dicts)),
    but the difference is that nested dicts can
    be passed as well.

    It was written to merge translation maps, the
    first being the default one (fallback) and the
    second one having priority. However, we wrote
    the function in a way that any number of dicts
    can be merged, with first dicts having priority
    over the last ones for defining leaves.

    Parameters
    ==========
    *dicts (mappings)
        mappings to be merged; mappings passed first
        have priority when defining leaves.
    
nodezator/ourstdlibs/treeutils.py