TypeError: unhashable type: 'list'
时间: 2023-10-21 16:17:26 浏览: 46
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)}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)