【发布时间】:2023-03-25 16:45:02
【问题描述】:
我有两个不同的字典列表,
list1 = [{'count': 351, 'att_value': 'one'},
{'count': 332, 'att_value': 'two'},
{'count': 336, 'att_value': 'six'},
{'count': 359, 'att_value': 'nine'},
{'count': 304, 'att_value': 'four'}]
list2 = [{'count': 359,'person_id' : 4},
{'count': 351, 'person_id' : 12},
{'count': 381, 'person_id' : 8}]
如何通过像 list_C 一样包含键的其余部分,基于“count”键找到 list_A 与 list_B 的交集?
list3 = [{'count':359, 'att_value' : 'nine', 'person_id':4},
{'count':351, 'att_value' : 'one', 'person_id':12},
{'count':381, 'att_value' : '-', 'person_id':8}]
我想保留 list2 中的键,但 list1 中的缺失值用“-”表示。
【问题讨论】:
标签: python python-3.x list dictionary