edata = [{"resource_id": "test", "operation_status": "change"},
{"resource_id": "test", "operation_status": "create"},
{"resource_id": "test1","operation_status": "change"},
{"resource_id": "test1","operation_status": "delete"}]
new_s = [] # 存储去重后的数据
for x in edata: # 根据字典列表的resource_id做去重操作
if any(str(d.get('resource_id', None)).lower() == str(x['resource_id']).lower() for d in new_s):
pass
else:
new_s.append(x)
print(new_s)
python字典列表根据字段key去重
最新推荐文章于 2026-03-28 02:35:48 发布
本文提供了一个Python示例代码,展示了如何去除包含重复资源ID的操作记录列表中的重复项。通过遍历列表并对比resource_id字段来实现这一目标。
1706

被折叠的 条评论
为什么被折叠?



