class Vertex: # vertex = node
def __init__(self, node):
self.id = node
self.adjacent = {}
def __str__(self):
return str(self.id) + ' adjacent: ' + str([x.id for x in self.adjacent])
I am not sure how to create an adj list!
我不知道如何创建一个形容词列表!
I tried a bunch of things but I usually get an error which looks something like:
我尝试了很多方法,但通常都会出现类似如下的错误:
bound<method vertex
( Sorry, I'm not getting this error anymore so I'm not entirely sure what it was )
(对不起,我不再收到这个错误,所以我不能完全确定它是什么)
I'm very stuck so any help is greatly appreciated. Thank you.
我被困住了,所以任何帮助我都非常感激。谢谢。
更多回答
not getting this error anymor - so what's the current error?
任何时候都没有得到这个错误-那么现在的错误是什么呢?
@RomanPerekhrest No clue what to try now.
@RomanPerekhrest现在不知道该尝试什么。
what adjacent
should contain? Other Vertex
? Where is the code that adds something to adjacent
?
相邻的应该包含什么?其他顶点?向相邻项添加内容的代码在哪里?
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
请编辑问题以将其限制为特定问题,并提供足够的详细信息以确定适当的答案。
优秀答案推荐
I believe that the below is what you are looking for
我相信下面的就是你要找的
class Vertex:
def __init__(self, node):
self.id = node
self.adjacent = []
def __str__(self):
return str(self.id) + ' adjacent: ' + str([x.id for x in self.adjacent])
v1 = Vertex('12')
v1.adjacent.append(Vertex('122'))
v1.adjacent.append(Vertex('123'))
print(v1)
output
输出
12 adjacent: ['122', '123']
更多回答
我是一名优秀的程序员,十分优秀!