def _implant_nodes(tree, branch):
    """Implant nodes of branch in the given tree.

    common nodes and leaf nodes are only implanted if they
    do not already exist in the tree.

    Parameters
    ==========
    tree (dict)
        the dictionary wherein to implant the nodes.

    branch (dict)
        represents a branch; its 'leaf' key has
        a leaf node and its 'stem' key has a
        list of all nodes from the first to
        the last one leading to the leaf.
    """
    ### retreive stem and leaf of branch

    stem = branch["stem"]
    leaf = branch["leaf"]

    ### since we'll use list.pop() to obtain
    ### each node of the stem, we reverse its
    ### order so the first ones are popped out
    ### first from the end of the list
    stem.reverse()

    ### while not reaching the break point...

    while True:

        ### pop a node from the stem
        node = stem.pop()

        ### if there are no nodes left in the stem...

        if not stem:

            ## if the node isn't in the tree, plant
            ## the leaf there

            if node not in tree:
                tree[node] = leaf

            ## break out of the "while loop"
            break

        else:

            ## if the node isn't in the tree, plant
            ## an empty dict there, and make the
            ## dict the new tree, by assigning it
            ## to the tree variable;
            ##
            ## note that these assignment operations
            ## would NOT work if chained like so:
            ## tree = tree[node] = {}

            if node not in tree:

                tree[node] = {}
                tree = tree[node]

            else:
                tree = tree[node]
Implant nodes of branch in the given tree.

    common nodes and leaf nodes are only implanted if they
    do not already exist in the tree.

    Parameters
    ==========
    tree (dict)
        the dictionary wherein to implant the nodes.

    branch (dict)
        represents a branch; its 'leaf' key has
        a leaf node and its 'stem' key has a
        list of all nodes from the first to
        the last one leading to the leaf.
    
nodezator/ourstdlibs/treeutils.py