I have two lists of dict
listA = [{'id': 'abc', 'key1': '542696d8485b'}]
listB = [{'id': 'abc', 'key1': '542696d8485b'}, {'id': 'def', 'key1': '27348628grn'}]
I want to extract listC = [{'id': 'abc', 'key1': '542696d8485b'}]
i.e I want to find intersection based on 'id' field( based on any one field, assuming common items in list are exactly same ). Suggest me some efficient pythonic way...
How about something like
listA_set = set(item['id'] for item in listA)
listB_set = set(item['id'] for item in listB)
listC_set = listA_set & listB_set
listC = {item:listA[item] for item in listC_set}