unhashable type: 'list'
时间: 2023-10-21 21:08:20 浏览: 37
This error occurs when trying to use a list as a key in a dictionary or as an element in a set. Lists are mutable, which means they can be changed after they are created. However, dictionary keys and set elements must be hashable, which means they cannot be changed after they are created.
To fix this error, you can use a tuple instead of a list as a key in a dictionary or as an element in a set. Tuples are immutable, so they can be hashed and used as dictionary keys or set elements.
For example, instead of using a list as a key in a dictionary:
```
my_dict = {[1, 2]: 'value'}
```
You can use a tuple:
```
my_dict = {(1, 2): 'value'}
```
Similarly, instead of using a list as an element in a set:
```
my_set = {[1, 2]}
```
You can use a tuple:
```
my_set = {(1, 2)}
```
相关推荐
![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_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)