sets

sets(G, top_nodes=None)[source]

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 documentation for further details on how bipartite graphs are handled in NetworkX.

Parameters
GNetworkX graph
top_nodescontainer, 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.

Returns
Xset

Nodes from one side of the bipartite graph.

Yset

Nodes from the other side.

Raises
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.

See also

color

Examples

>>> from networkx.algorithms import bipartite
>>> G = nx.path_graph(4)
>>> X, Y = bipartite.sets(G)
>>> list(X)
[0, 2]
>>> list(Y)
[1, 3]