dicionário – Python : Build a Graph with maps of sets


Hello this is my first post and I’m not fluent in English, so forgive me if I do any wrong post protocol ….

so, I have this current implementation of a graph, through an adjacency matrix:

class GFG: 
def __init__(self,graph): 
    self.graph = graph

from which I start like this:

my_shape = (N,M)
bpGraph = np.zeros(my_shape)

and add edges like this:

vertex_a = 2
vertex_b = 5
bpGraph (vertex_a, vertex_b) = 1
g = GFG(bpGraph)

and check for an edge like this:

if bpGraph (vertice_a, vertice_b):
do something...

But this type of structure can take a lot of space if I have a lot of vertices, so I would like to switch to a set map

class GFG: 
def __init__(self,N,M):
    mysetdict = {
        "dummy_a": {"dummy_b","dummy_c"},
    }
    self.graph = mysetdict 

def add_edges(self,N,M):
    N_set = {}
    if str(N) in self.graph:
        N_set = self.graph(str(N))
    N_set.add(str(M))

    self.graph(str(N)) = N_set

def check_edges(self,N,M):
     return str(M) in self.graph(str(N))

When I try to add a vertex I get this error:

g = GFG (3,4)
g.add_edges (0, 0)
AttributeError: 'dict' object has no attribute 'add'
---> 16                 N_set.add(str(M))

im trying many ways to build this set and check if a entry exists before add a vertex_a to do a edge with vertex_b, but all my tryes results in a atribute error.

any suggestions?