欢迎各位兄弟 发布技术文章
这里的技术是共享的
list1 [{"field_person_gh":"1111","field_manager_gh":"4444"},{"field_person_gh":"2222","field_manager_gh":"5555"} list2 [{"field_person_gh":"1111","field_manager_gh":"6666"},{"field_person_gh":"3333","field_manager_gh":"7777"} 的 list2 中移除 field_person_gh 相等的值 ,,比如这里移除 {"field_person_gh":"1111","field_manager_gh":"6666"} 用 python 来实现
你可以使用以下 Python 代码从 list2 中移除 field_person_gh 值与 list1 中相等的字典项:
提取值:
使用集合推导式 {item["field_person_gh"] for item in list1} 提取 list1 中所有的 field_person_gh 值。
过滤 list2:
使用列表推导式 [item for item in list2 if item["field_person_gh"] not in field_person_gh_values] 过滤掉 field_person_gh 在 field_person_gh_values 中的项。
运行上述代码后,filtered_list2 将只包含 {"field_person_gh": "3333", "field_manager_gh": "7777"},因为 {"field_person_gh": "1111", "field_manager_gh": "6666"} 被移除了。