a=[[1, 'HAA712AP5', '@3限速器钢丝绳', 49, 'MT', '', None, None, '301172'], [1, 'DCA20602C98', '@0限速器钢丝绳出厂包', 1, 'EA', '', None, None, '301172'], [1, 'DCA20602C99', '@0限速器钢', 1, 'EA', '', None, None, '301172']] b=[[1, 'DCA20602C98', '@0限速器钢丝绳出厂包', 1, 'EA', '', None, None, '301172'], [1, 'DCA20602C99', '@0限速器钢', 1, 'EA', '', None, None, '301172']] 找出ab不同的元素
时间: 2023-10-23 19:33:25 浏览: 430
基于SD45230 USB智能识别车载充电器ALTIUM硬件原理图PCB+3D集成封装库.zip
5星 · 资源好评率100%
可以使用列表推导式和not in运算符来找出a和b中不同的元素:
```python
a = [[1, 'HAA712AP5', '@3限速器钢丝绳', 49, 'MT', '', None, None, '301172'], [1, 'DCA20602C98', '@0限速器钢丝绳出厂包', 1, 'EA', '', None, None, '301172'], [1, 'DCA20602C99', '@0限速器钢', 1, 'EA', '', None, None, '301172']]
b = [[1, 'DCA20602C98', '@0限速器钢丝绳出厂包', 1, 'EA', '', None, None, '301172'], [1, 'DCA20602C99', '@0限速器钢', 1, 'EA', '', None, None, '301172']]
diff_elements = [x for x in a if x not in b] + [x for x in b if x not in a]
print(diff_elements)
```
输出结果为:
```
[[1, 'HAA712AP5', '@3限速器钢丝绳', 49, 'MT', '', None, None, '301172']]
```
说明a中有一个元素不在b中,为`[1, 'HAA712AP5', '@3限速器钢丝绳', 49, 'MT', '', None, None, '301172']`。
阅读全文