Returns bipartite node sets of graph G.
Raises an exception if the graph is not bipartite or if the input graph is disconnected and thus more than one valid solution exists. See
bipartite documentationfor further details on how bipartite graphs are handled in NetworkX.
G (NetworkX graph)
top_nodes (container, optional) – Container with all nodes in one bipartite node set. If not supplied it will be computed. But if more than one solution exists an exception will be raised.
X (set) – Nodes from one side of the bipartite graph.
Y (set) – Nodes from the other side.
AmbiguousSolution – Raised if the input bipartite graph is disconnected and no container with all nodes in one bipartite set is provided. When determining the nodes in each bipartite set more than one valid solution is possible if the input graph is disconnected.
NetworkXError – Raised if the input graph is not bipartite.
>>> from networkx.algorithms import bipartite >>> G = nx.path_graph(4) >>> X, Y = bipartite.sets(G) >>> list(X) [0, 2] >>> list(Y) [1, 3]