def match_hierarchy(source, target):
    """Matches the objects in two different hierarchy by looking at their
    names.

    Returns a dictionary where you can look up for matches by using the object
    name.
    """
    source_nodes = source.listRelatives(
        ad=1,
        type=(pm.nt.Mesh, pm.nt.NurbsSurface)
    )
    target_nodes = target.listRelatives(
        ad=1,
        type=(pm.nt.Mesh, pm.nt.NurbsSurface)
    )

    source_node_names = []
    target_node_names = []

    lut = {
        'match': [],
        'no_match': []
    }
    for node in source_nodes:
        name = node.name().split(':')[-1].split('|')[-1]
        source_node_names.append(name)

    for node in target_nodes:
        name = node.name().split(':')[-1].split('|')[-1]
        target_node_names.append(name)

    for i, target_node in enumerate(target_nodes):
        target_node_name = target_node_names[i]
        try:
            tmp_target_node_name = target_node_name
            if target_node_name.endswith('Deformed'):
                tmp_target_node_name = \
                    target_node_name.replace('Deformed', '')
            index = source_node_names.index(tmp_target_node_name)
        except __HOLE__:
            lut['no_match'].append(target_node)
        else:
            lut['match'].append((source_nodes[index], target_nodes[i]))

    return lut
dataset/ETHPy150Open eoyilmaz/anima/anima/env/mayaEnv/auxiliary.py/match_hierarchy