def pathCost(path, g, wt="weight"):
    """ Compute the cost of the given path in a graph.

    Parameters
    ----------
    path : list
        a path given as a node list.
    g : networkx.Graph
        a networkx graph or directed graph where links have some type of weight attribute.
    wt : string
        (optional) the name of the link attribute to be used to compute the (additive) path cost.

    Returns
    -------
    cost : float
        The total cost of the path.
    """
    cost = 0.0
    for i in range(len(path)-1):
        if not g.has_edge(path[i], path[i+1]):
            raise Exception('Bad Path')
        else:
            cost += g[path[i]][path[i+1]][wt]
    return cost