contract_nodes(G, nbunch, new_node=None)¶
Contract the nodes in nbunch.
Contracting a set S of nodes in a graph G first removes the nodes in S from G then creates a new node v with new edges (v, u) for all nodes u that are neighbors of a nodes in S.
- G (NetworkX graph) – An undirected graph.
- nbunch – A single node or iterable container of nodes in G.
- new_node – The node to be added. If no node is given, it defaults to the minimum node in nbunch according to the natural ordering of nodes.
This method does not return a value. It alters the graph in place.