In [ ]:
n = int(input("number of nodes: "))
m = int(input("number of edges: "))

In [ ]:
E={}
V={ i:[] for i in list(range(n))}
#V[1].append(1)
for i in range(m):
    E[i]=list(map(int, input("E["+str(i)+"]: ").split()))
    V[int(E[i][0])].append(int(E[i][1]))

In [3]:
print("Edges list: " + str(E))
print("Adjacency list: "+ str(V))


Edges list: {0: [0, 1], 1: [1, 2], 2: [2, 3], 3: [2, 4], 4: [3, 4]}
Adjacency list: {0: [1], 1: [2], 2: [3, 4], 3: [4], 4: []}

In [10]:
print("Adjacency matrix: ")
fs = lambda i,j: int(j in V[i])
for i in range(n):
    print(list(fs(i,j) for j in range (n)))


Adjacency matrix: 
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]

In [37]:
fi = lambda i,j: int(j in E[i])
print("Adjacency matrix: ")
for j in range(m):
    print(list(fi(i,j) for i in range (n)))


Adjacency matrix: 
[1, 0, 0, 0, 0]
[1, 1, 0, 0, 0]
[0, 1, 1, 1, 0]
[0, 0, 1, 0, 1]
[0, 0, 0, 1, 1]

In [ ]: