📌  相关文章
📜  TypeError: unhashable type: 'list' python dictionary - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:39.486000             🧑  作者: Mango

代码示例1
The error you gave is due to the fact that in python, dictionary keys must be immutable types (if key can change, there will be problems), and list is a mutable type.

Your error says that you try to use a list as dictionary key, you'll have to change your list into tuples if you want to put them as keys in your dictionary.

According to the python doc :

The only types of values not acceptable as keys are values containing lists or dictionaries or other mutable types that are compared by value rather than by object identity, the reason being that the efficient implementation of dictionaries requires a key’s hash value to remain constant