How to get a vertex list of differences between two graphs in igraph
<p>I'm trying to get a list of vertex that are present or missing from a graph 1 against another graph 2. I'm wondering if there any helper method in igraph to do it or if would be necessary to build a own. Thank you.</p>

<p>I don't think there's a builtin method within graph that does what you want. However, it is straightforward to make your own.</p>

<p>I'm going to make the reasonable assumption here that the unique identifier of a vertex is the 'name' property that igraph encourages users to use. Essentially, you make two sets of the names of vertices in graph1 and the names of vertices in graph2 and compute their difference. Then you can search graph1 for the vertex that corresponds to that name and add it to a list to return:</p>

<pre><code>def find_diff(graph1, graph2):
    """
    Returns list of vertices that are present in graph1 but missing in graph2
    """
    set_v1 = set(graph1.vs['name'])  # set of names of vertices in graph1
    set_v2 = set(graph2.vs['name'])  # set of names of vertices in graph2
    diff = set_v1 - set_v2 
    result = []
    for vname in diff:
        result.append(graph1.vs.find(name=vname))     # find vertex that corresponds to name in graph1 and append it to list

    return result
</code></pre>

<p>The above code is for clarity. You can actually do it in a faster and shorter way. Here's a one liner:</p>

<pre><code>def find_diff(graph1, graph2):
    """
    Returns list of vertices that are present in graph1 but missing in graph2
    """
    return [vx for vx in graph1.vs if vx['name'] not in graph2.vs['name']]
</code></pre>

python igraph