I have two lists of dictionaries in the format:
systolic_sex = [
{'attribute': u'bp', 'value_d': 133.0, 'value_s': u'133', 'sid': 6},
{'attribute': u'bp', 'value_d': 127.0, 'value_s': u'127', 'sid': 17},
{'attribute': u'bp', 'value_d': 121.0, 'value_s': u'121', 'sid': 18},
{'attribute': u'bp', 'value_d': 127.0, 'value_s': u'127', 'sid': 27},
{'attribute': u'bp', 'value_d': 120.0, 'value_s': u'120', 'sid': 42},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 6},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 17},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 18},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 27},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 42}
]
sex = [
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 6},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 17},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 42}
]
I want to match these lists by the value of the key 'sid,' so that if the same value of 'sid' is in both, I have a match, otherwise, I do not. If I have a match, I then append the matching dictionaries by 'sid' from both sets to a new list accordingly like so
new_set = [
{'attribute': u'bp', 'value_d': 133.0, 'value_s': u'133', 'sid': 6},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 6},
{'attribute': u'bp', 'value_d': 127.0, 'value_s': u'127', 'sid': 17},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 17},
{'attribute': u'bp', 'value_d': 120.0, 'value_s': u'120', 'sid': 42},
{'attribute': u'SEX', 'value_d': 0.0, 'value_s': u'M', 'sid': 42}
]
I've tried various methods of intersecting these, including modifying answers from Match set of dictionaries, but I am looking to create a new list of dictionaries that have the matching sids, not replacing values between the two lists.