def weight_path(spec_path, element_path):
    """Determine the weighting number for a matchingRule path spec applied to an actual element path from a
    response body.

    Both paths are passed in as lists which represent the paths split per split_path()

    In spec version 2 paths should always start with ['$', 'body'] and contain object element names or array indexes.

    In spec version 3 the path "context" element (like 'body') is moved outside of the path, and the path contains
    just the elements inside the path, always starting at the root '$', so the shortest path is now ['$'].

    Weighting is calculated as:

    * The root node ($) is assigned the value 2.
    * Any path element that does not match is assigned the value 0.
    * Any property name that matches a path element is assigned the value 2.
    * Any array index that matches a path element is assigned the value 2.
    * Any star (*) that matches a property or array index is assigned the value 1.
    * Everything else is assigned the value 0.

    Return the numeric score.
    """
    if len(spec_path) != len(element_path):
        return 0
    score = 1
    for spec, element in zip(spec_path, element_path):
        if spec == element:
            score *= 2
        elif spec == '*':
            score *= 1
        else:
            return 0
    return score