def union(G, H, rename=(None, None), name=None):
    # Union is the same type as G
    R = G.__class__()
    if name is None:
        name = "union( %s, %s )"%(G.name,H.name)
    R.name = name

    # rename graph to obtain disjoint node labels
    def add_prefix(graph, prefix):
        if prefix is None:
            return graph
        def label(x):
            if is_string_like(x):
                name=prefix+x
            else:
                name=prefix+repr(x)
            return name
        return nx.relabel_nodes(graph, label)
    G = add_prefix(G,rename[0])
    H = add_prefix(H,rename[1])
    if set(G) & set(H):
        raise nx.NetworkXError('The node sets of G and H are not disjoint.',
                               'Use appropriate rename=(Gprefix,Hprefix)'
                               'or use disjoint_union(G,H).')
    if G.is_multigraph():
        G_edges = G.edges_iter(keys=True, data=True)
    else:
        G_edges = G.edges_iter(data=True)
    if H.is_multigraph():
        H_edges = H.edges_iter(keys=True, data=True)
    else:
        H_edges = H.edges_iter(data=True)

    # add nodes
    R.add_nodes_from(G)
    R.add_edges_from(G_edges)
    # add edges
    R.add_nodes_from(H)
    R.add_edges_from(H_edges)
    # add node attributes
    R.node.update(G.node)
    R.node.update(H.node)
    # add graph attributes, H attributes take precedent over G attributes
    R.graph.update(G.graph)
    R.graph.update(H.graph)


    return R
Return the union of graphs G and H.
dataset/ETHPy150Open gkno/gkno_launcher/src/networkx/algorithms/operators/binary.py/union