python - 查找字典 Python 列表的差异

标签 python list dictionary set

我在 Python 中有 2 个列表;

listA = [{'b': '3'}, {'b': '4'}]
listB = [{'a': '3'}, {'b': '3'}]

我试图将它转换为设置它显示不可散列的类型:'dict'

我试图做的操作是
list[(set(listA)).difference(set(listB))]

那么我的列表可以做什么来实现相同的功能?谢谢

最佳答案

用简单的列表理解来做。

>>> [i for i in listA if i not in listB]
[{'b': '4'}]

关于python - 查找字典 Python 列表的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44491804/

相关文章:

python - 计算列表中的元素会产生意外结果

c++ - QML map : Large amount of displayed items

python - 使用索引和列名称给定的键将数据帧展平为字典

python - 使用递归来反转 python 中的列表?

c# - 如何创建包含开放通用接口(interface)的 List<T> ?

python - 使用 dict.get() 的斐波那契数列和 RecursionError

python - 如何将python文本添加到HTML网站?

python - 使用 Python 沙盒化 Web 服务

python - 在 Python 中实现传输层安全 - 简单的邮件客户端

python - QGtkStyle 无法解析 GTK