TypeError: unhashable type: 'list'
时间: 2023-10-21 18:17:26 浏览: 77
This error message indicates that you are trying to use a list as a key in a dictionary or as an element in a set. However, lists are not hashable, which means they cannot be used as keys or elements in these data structures.
To fix this error, you can use a tuple instead of a list as the key or element. Tuples are immutable and therefore hashable, which makes them suitable for use in dictionaries and sets.
For example, instead of using a list like this:
```
my_dict = {[1, 2]: 'value'}
```
You can use a tuple like this:
```
my_dict = {(1, 2): 'value'}
```
Similarly, instead of using a list like this:
```
my_set = {[1, 2], [3, 4]}
```
You can use a tuple like this:
```
my_set = {(1, 2), (3, 4)}
```
阅读全文