This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
common_neighbors(G, u, v)¶
Return the common neighbors of two nodes in a graph.
- G (graph) – A NetworkX undirected graph.
- v (u,) – Nodes in the graph.
cnbors – Iterator of common neighbors of u and v in the graph.
NetworkXError– If u or v is not a node in the graph.
>>> G = nx.complete_graph(5) >>> sorted(nx.common_neighbors(G, 0, 1)) [2, 3, 4]