class _Edges(defaultdict):
def __missing__(self, vertex):
self.setdefault(vertex, True)
def __delitem__(self, dst):
self[dst] = False
def del_vertex(self, dst):
super().__delitem__(dst)
class Graph(defaultdict):
def __init__(self):
super().__init__(_Edges)
def copy(self):
return super().__copy__()
I'm trying to write a class that makes a graph but when I try to call the copy function I get the error. Should I write my own __copy__
? I thought that I could use defaultdict
's copy to copy the graph.
The copy class is supposed to create an exact copy of the graph by calling graph.copy()
ex.
g = Graph()
g['a']['b'] = 5
x = g.copy()
This would make an exact copy but i get the error stated above instead