I'm trying to implement an adjacency list by using the text file which includes:
0,1,5,1,3,1,0,3,1,1,0,4,7,1,0,4,0,4,1,6,5,1,1,3,6,3,4,1,5,2
6,0,1,4,1,5,3,0,4,5,1,4,7,4,2,0,3,5,4,1,3,1,7,3,2,1,1,6,5,0
4,6,0,3,1,6,1,6,2,1,2,2,7,7,7,1,1,1,6,1,1,5,1,6,1,6,1,2,5,3
6,4,5,0,4,1,6,1,6,2,1,0,6,5,1,3,0,1,0,7,5,1,6,6,3,2,3,1,6,4
4,2,0,6,0,0,4,6,3,3,3,6,7,0,1,4,5,7,3,4,2,3,7,7,1,4,6,6,4,5
0,2,6,1,6,0,3,3,6,1,4,4,3,5,0,7,3,7,3,7,0,2,7,1,7,2,5,7,1,0
7,4,5,2,2,2,0,3,1,4,0,6,0,3,7,1,4,6,6,6,6,1,1,6,1,3,3,3,2,0
2,0,1,3,1,7,2,0,3,0,5,2,3,4,1,7,1,0,1,5,3,6,1,2,2,0,5,2,4,0
7,3,2,6,2,6,6,1,0,1,0,6,2,3,0,5,2,1,7,0,0,3,3,0,1,1,1,4,6,1
4,1,7,4,2,5,7,1,4,0,4,3,6,1,6,6,1,0,4,0,0,0,2,2,4,2,6,0,7,5
1,1,2,1,0,5,1,6,2,6,0,4,4,6,2,5,1,1,0,0,5,0,1,1,2,5,1,3,6,6
0,3,7,3,1,4,6,1,2,7,1,0,4,4,1,1,6,7,1,5,0,4,0,4,6,3,1,4,1,0
1,4,7,0,4,1,5,3,1,0,0,6,0,0,5,0,3,5,4,7,2,1,4,7,3,1,5,7,3,2
3,1,5,3,3,4,2,4,4,5,1,7,6,0,3,3,0,0,7,7,3,5,6,7,0,2,1,0,2,2
3,1,4,4,1,5,1,5,6,2,6,4,5,7,0,0,4,1,3,7,5,1,0,4,5,4,5,1,1,0
Think of every line has the index number as the name instead of A,B,C.... So for example 0,1,5,1,3,1,0,3,1,1,0,4,7,1,0,4,0,4,1,6,5,1,1,3,6,3,4,1,5,2 is the node 0 and 6,0,1,4,1,5,3,0,4,5,1,4,7,4,2,0,3,5,4,1,3,1,7,3,2,1,1,6,5,0 is the node 1 etc. The problem here is I cannot extract elements because of the "," between each element. I tried this:
a = np.array([])
with open("routers.txt") as f:
adj_list = list(f)
node_no = 0
node_list = list()
for i in adj_list:
node_list.append(node_no)
if i[node_no] != ",":
a = np.append(a, i[node_no])
node_no += 1
elif i[node_no] == ",":
break
But it cannot go further, when it sees "," it stops.