My code generates the following error: TypeError: object() takes no parameters
class Graph(object):
def vertices(self):
return list(self.__graph_dict.keys())
if __name__ == "__main__":
g = { "a" : ["d"],
"b" : ["c"],
"c" : ["b", "c", "d", "e"],
"d" : ["a", "c"],
"e" : ["c"],
"f" : []
}
graph = Graph(g)
print("Vertices of graph:")
print(graph.vertices())
Is there a way I can solve this?
Your Graph class takes no arguments on __init__
therefore when you call:
graph = Graph(g)
You get an error because Graph doesn't know what to do with 'g'. I think what you may want is:
class Graph(object):
def __init__(self, values):
self.__graph_dict = values
def vertices(self):
return list(self.__graph_dict.keys())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.