不可损坏类型:“Vertex”

2024-09-27 00:21:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到以下错误:

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}$

Tags: 函数inpyselfadd定义错误line

热门问题