Python的两个字典列表的交集
发布时间:2020-12-20 11:46:50 所属栏目:Python 来源:网络整理
导读:我有2个像dic的列表 list1 = [{'count': 351,'evt_datetime': datetime.datetime(2015,10,23,8,45),'att_value': 'red'},{'count': 332,{'count': 336,{'count': 359,{'count': 309,'att_value': 'red'}]list2 = [{'count': 359,{'count': 351,{'count': 381
我有2个像dic的列表
list1 = [{'count': 351,'evt_datetime': datetime.datetime(2015,10,23,8,45),'att_value': 'red'},{'count': 332,{'count': 336,{'count': 359,{'count': 309,'att_value': 'red'}] list2 = [{'count': 359,{'count': 351,{'count': 381,22,'att_value': 'red'}] 我试图从列表中得到共同的词汇.我想要的输出是dict的键和值的精确匹配. [{'count': 359,'att_value': 'red'}] 这可以通过python本身有效地完成,还是需要lib像pandas? 解决方法
使用列表理解:
[x for x in list1 if x in list2] 这会返回我的数据列表: [{'count': 351,'att_value': 'red'}] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |