I'm a newbie to Python (and computer science in general), so bear with me.
I'm having trouble implementing an adjacency list in Python. I have learned how to implement it through a dictionary (I learned how through here lol), but I need to know how to do it using only basic lists (list of lists)
This is my code:
with open("graph1.txt") as infile:
vertices = []
for line in infile:
line = line.split()
line = [int(i) for i in line]
vertices.append(line)
adj = dict()
for edge in vertices:
x, y = int(edge[0]), int(edge[1])
if x not in adj: adj[x] = set()
if y not in adj: adj[y] = set()
adj[x].add(y)
adj[y].add(x)
print(adj)
Any help is appreciated. Cheers
vertices, but it's a list of edges?