Bjö*_*lex 15

看起来你正在尝试使用列表作为字典中的键或类似的东西.列表不可清除,因此它们不能用作字典键或集合.

另一方面,python在发生此类错误时为您提供堆栈跟踪,其中包括文件名和行号.您应该能够使用该跟踪来查找有问题的代码.

编辑关于stacktraces:

cat > script.py
foo = [1,2,3]
bar = {}
bar[foo] = "Boom"
print "Never happens"

python script.py
Traceback (most recent call last):
  File "script.py", line 3, in <module> // this is the file and the line-number
   bar[foo] = "Boom"
TypeError: unhashable type: 'list'
Run Code Online (Sandbox Code Playgroud)

  • @Shilpa:现在你的问题毫无意义.没有.零. (2认同)

Mat*_*ner 6

您可能尝试使用可变对象(如列表)作为字典的键或作为集合的成员.无法有效且可预测地跟踪可变项以用于此类用途,因此它们不提供散列特殊属性.