def getWeightedNodes(nodes, weights):
    """Takes list of nodes (rel_stats) and weights (as a dict) and outputs
    a list of (node, cum_weight) pairs, where cum_weight is the cumulative
    probability of the nodes weighted by weights.
    """
    # compute total weight
    total_weight = sum([float(weights[n]) for n in nodes])
    if total_weight == 0:
        raise ValueError('Error: Node list has total weight zero.')

    # create cumulative weights
    weighted_nodes = []
    cum_weight = 0
    for node in nodes:
        cum_weight += weights[node] / total_weight
        weighted_nodes.append((node, cum_weight))

    return weighted_nodes