convert bipartite graph to adjacency matrix python

I'm trying to convert edge list which is in the following format

data = [('a', 'developer'),
         ('b', 'tester'),
        ('b', 'developer'),
         ('c','developer'),
         ('c', 'architect')]

where the adjacency matrix will be in the form of

      developer     tester    architect
a        1            0          0
b        1            1          0
c        1            0          1

I want to store the matrix in the following format

 1    0    0
 1    1    0
 1    0    1

Any help is highly appreciated

Answers


This can be done easily with networkx:

from operator import itemgetter

import networkx as nx
from networkx.algorithms.bipartite import biadjacency_matrix

def to_adjacency_matrix(data):
    g = nx.DiGraph()
    g.add_edges_from(data)
    partition_1 = set(map(itemgetter(0), data))
    return biadjacency_matrix(g, partition_1).toarray()

Need Your Help

How can I disable "Welcome to mapbox" marker

leaflet mapbox

Every time I open the mapbox map (paid plan) there is a "welcome to mapbox" marker. How can I disable / hide this?

Generate Gauss numbers

c# algorithm physics

I have this problem with generating Gauss Numbers. The problem is like this :