'list' object has no attribute 'union'
时间: 2023-10-30 22:03:22 浏览: 268
python报错: 'list' object has no attribute 'shape'的解决
5星 · 资源好评率100%
It seems like you are trying to use the `union` method on a list object. However, the `union` method is not available for lists in Python. The `union` method is used for set objects instead. If you want to combine two lists and remove duplicates, you can convert them to sets and then convert the result back to a list. Here's an example:
```python
list1 = [1, 2, 3]
list2 = [2, 3, 4]
combined_list = list(set(list1).union(set(list2)))
```
In this example, `combined_list` will contain `[1, 2, 3, 4]`.
阅读全文