Python 两个 List of Dict 去重

简介: Python 两个 List of Dict 去重

有两个 List Of Dict


a = [{"1":1},{"2":2}]
b =  [{"1":1},{"3":3}]


现在要求出在 a 数组中的 dict 而不在 b 中的 dict


用列表解析式就可以,dict 默认实现了 __eq__ 方法(底层比较利用了 __hash__) 方法


image.png


更多的内容可以参考 C 的源码


https://github.com/python/cpython/blob/main/Objects/dictobject.cgithub.com/python/cpython/blob/main/Objects/dictobj

目录
相关文章
|
6天前
|
SQL 机器学习/深度学习 算法
【python】python指南(五):静态类型注解之List
【python】python指南(五):静态类型注解之List
12 0
【python】python指南(五):静态类型注解之List
|
6天前
|
JSON 算法 算法框架/工具
【python】python指南(十二):Json与dict、list互相转换
【python】python指南(十二):Json与dict、list互相转换
6 0
|
12天前
|
索引 Python
【Leetcode刷题Python】从列表list中创建一颗二叉树
本文介绍了如何使用Python递归函数从列表中创建二叉树,其中每个节点的左右子节点索引分别是当前节点索引的2倍加1和2倍加2。
15 7
|
27天前
|
Python
|
6天前
|
SQL 机器学习/深度学习 算法
【python】python指南(六):静态类型注解之Dict
【python】python指南(六):静态类型注解之Dict
12 0
|
14天前
|
Python
【Python】对key或values是datetime类型或时间字符串的字典dict排序
本文提供了针对字典中key为时间字符串或datetime类型时进行排序的解决方案,包括将时间字符串转换为datetime对象排序和直接对datetime类型的key排序的方法。
25 0
|
1月前
|
存储 缓存 Python
Python中的列表(List)和元组(Tuple)是两种重要的数据结构
【7月更文挑战第12天】Python中的列表(List)和元组(Tuple)是两种重要的数据结构
24 1
|
1月前
|
存储 索引 Python
【Python】已解决:IndexError: list index out of range
【Python】已解决:IndexError: list index out of range
73 1
|
1月前
|
存储 算法 索引
python dict字典
python dict字典
|
1月前
|
开发者 Python
【Python】已解决:TypeError: descriptor ‘index‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
【Python】已解决:TypeError: descriptor ‘index‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
35 0