returns links that have changed cost

def _find_changed(old, new, both):
    """
    returns links that have changed cost
    """
    # create two list of sets of old and new edges including cost
    old_edges = []
    for edge in old.edges(data=True):
        # skip links that are not in both
        if set((edge[0], edge[1])) not in both:
            continue
        # wrap cost in tuple so it will be recognizable
        cost = (edge[2]['weight'],)
        old_edges.append(set((edge[0], edge[1], cost)))
    new_edges = []
    for edge in new.edges(data=True):
        # skip links that are not in both
        if set((edge[0], edge[1])) not in both:
            continue
        # wrap cost in tuple so it will be recognizable
        cost = (edge[2]['weight'],)
        new_edges.append(set((edge[0], edge[1], cost)))
    # find out which edge changed
    changed = []
    for new_edge in new_edges:
        if new_edge not in old_edges:
            # new_edge is a set, convert it to list
            new_edge = list(new_edge)
            for item in new_edge:
                if isinstance(item, tuple):
                    # unwrap cost from tuple and put it in a dict
                    cost = {'weight': item[0]}
                    new_edge.remove(item)
            changed.append((new_edge[0], new_edge[1], cost))
    return changed