import networkx as nx
from networkx.algorithms import bipartite
X = set([1,2,3,4,5,6,7,8])
Y = set(['A','B','C','D','E','F'])
B = nx.Graph()
B.add_nodes_from(X, bipartite=0)
B.add_nodes_from(Y, bipartite=1)
B.add_edges_from([
(1,'A'),(1,'B'),(2,'A'),(2,'B'),(2,'D'),(3,'C'),(3,'E'),(4,'A'),(4,'D'),
(5,'C'),(5,'E'),(6,'C'),(6,'F'),(7,'E'),(7,'F'),(8,'E')
])