我得到以下错误:
Traceback (most recent call last):
File "dijkastras.py", line 146, in <module>
g.add_edge(vertices[i], k[0], int(k[1]))
File "dijkastras.py", line 82, in add_edge
self.vertices[frm].add_neighbour(self.vertices[to], weight)
File "dijkastras.py", line 16, in add_neighbour
self.adjacent[neighbour] = weight
TypeError: unhashable type: 'Vertex'
我知道定义一个__eq__
意味着默认的散列函数消失了,我必须重新定义__hash__
方法,但我不知道如何去做。有人能建议一个哈希函数的实现吗?
提前谢谢。在
这是我的密码。在
^{pr2}$
也许可以尝试添加顶点:
(您还可以选择不同属性的组合,而不仅仅是id;您选择的属性本身应该是散列的)。在
相关问题 更多 >
编程相关推荐