(graphs)
return graph_union
Graph disjoint union.

    The disjoint union of two or more graphs is created.

    This function keeps the attributes of all graphs. All graph, vertex and
    edge attributes are copied to the result. If an attribute is present in
    multiple graphs and would result a name clash, then this attribute is
    renamed by adding suffixes: _1, _2, etc.

    An error is generated if some input graphs are directed and others are
    undirected.

    @param graphs: list of graphs. A lazy sequence is not acceptable.
    @return: the disjoint union graph
Graph disjoint union.
Graph disjoint union .
def disjoint_union(graphs):
    """Graph disjoint union.

    The disjoint union of two or more graphs is created.

    This function keeps the attributes of all graphs. All graph, vertex and
    edge attributes are copied to the result. If an attribute is present in
    multiple graphs and would result a name clash, then this attribute is
    renamed by adding suffixes: _1, _2, etc.

    An error is generated if some input graphs are directed and others are
    undirected.

    @param graphs: list of graphs. A lazy sequence is not acceptable.
    @return: the disjoint union graph
    """
    if any(not isinstance(g, GraphBase) for g in graphs):
        raise TypeError("Not all elements are graphs")

    ngr = len(graphs)
    # Trivial cases
    if ngr == 0:
        raise ValueError("disjoint_union() needs at least one graph")
    if ngr == 1:
        return graphs[0].copy()
    # Now there are at least two graphs

    graph_union = _disjoint_union(graphs)

    # Graph attributes
    # NOTE: a_first_graph tracks which graph has the 1st occurrence of an
    # attribute, while a_conflict track attributes with naming conflicts
    a_first_graph = {}
    a_conflict = set()
    for ig, g in enumerate(graphs, 1):
        # NOTE: a_name is the name of the attribute, a_value its value
        for a_name in g.attributes():
            a_value = g[a_name]
            # No conflicts
            if a_name not in graph_union.attributes():
                a_first_graph[a_name] = ig
                graph_union[a_name] = a_value
                continue
            if graph_union[a_name] == a_value:
                continue
            if a_name not in a_conflict:
                # New conflict
                a_conflict.add(a_name)
                igf = a_first_graph[a_name]
                graph_union["{:}_{:}".format(a_name, igf)] = graph_union[a_name]
                del graph_union[a_name]
            graph_union["{:}_{:}".format(a_name, ig)] = a_value

    # Vertex attributes
    i = 0
    for g in graphs:
        nv = g.vcount()
        for attr in g.vertex_attributes():
            graph_union.vs[i : i + nv][attr] = g.vs[attr]
        i += nv

    # Edge attributes
    i = 0
    for g in graphs:
        ne = g.ecount()
        for attr in g.edge_attributes():
            graph_union.es[i : i + ne][attr] = g.es[attr]
        i += ne

    return graph_union
def disjoint_union ( graphs ) : if any ( not isinstance ( g , GraphBase ) for g in graphs ) : raise TypeError ( "Not all elements are graphs" ) ngr = len ( graphs ) # Trivial cases if ngr == 0 : raise ValueError ( "disjoint_union() needs at least one graph" ) if ngr == 1 : return graphs [ 0 ] . copy ( ) # Now there are at least two graphs graph_union = _disjoint_union ( graphs ) # Graph attributes # NOTE: a_first_graph tracks which graph has the 1st occurrence of an # attribute, while a_conflict track attributes with naming conflicts a_first_graph = { } a_conflict = set ( ) for ig , g in enumerate ( graphs , 1 ) : # NOTE: a_name is the name of the attribute, a_value its value for a_name in g . attributes ( ) : a_value = g [ a_name ] # No conflicts if a_name not in graph_union . attributes ( ) : a_first_graph [ a_name ] = ig graph_union [ a_name ] = a_value continue if graph_union [ a_name ] == a_value : continue if a_name not in a_conflict : # New conflict a_conflict . add ( a_name ) igf = a_first_graph [ a_name ] graph_union [ "{:}_{:}" . format ( a_name , igf ) ] = graph_union [ a_name ] del graph_union [ a_name ] graph_union [ "{:}_{:}" . format ( a_name , ig ) ] = a_value # Vertex attributes i = 0 for g in graphs : nv = g . vcount ( ) for attr in g . vertex_attributes ( ) : graph_union . vs [ i : i + nv ] [ attr ] = g . vs [ attr ] i += nv # Edge attributes i = 0 for g in graphs : ne = g . ecount ( ) for attr in g . edge_attributes ( ) : graph_union . es [ i : i + ne ] [ attr ] = g . es [ attr ] i += ne return graph_union