Answers for "TypeError: unhashable type: 'list' python dictionary"

1

TypeError: unhashable type: 'list' python dictionary

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
Posted by: Guest on July-13-2020

Code answers related to "TypeError: unhashable type: 'list' python dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language