I am new to python and I tried to google and find this one really similar to my case: combine dictionaries in list of dictionaries based on matching key:value pair but in my case suppose I have a list as below:
[{'entity': 'Mechanical properties',
'offsetstart': 0,
'offsetend': 21,
'id': 'c_4683'},
{'entity': 'properties',
'offsetstart': 11,
'offsetend': 21,
'id': 'c_49874'},
{'entity': 'properties',
'offsetstart': 11,
'offsetend': 21,
'id': 'c_13609'},
{'entity': 'wood',
'offsetstart': 33,
'offsetend': 37,
'id': 'c_8421'}]
How can I combine the value of the key "id" when matching multiple key:value pairs (i.e. the value of key "entity", "offsetstart", and "offsetend")
So I can get the desired result as below:
[{'entity': 'Mechanical properties',
'offsetstart': 0,
'offsetend': 21,
'id': 'c_4683'},
{'entity': 'properties',
'offsetstart': 11,
'offsetend': 21,
'id': ['c_49874', 'c_13609']},
{'entity': 'wood',
'offsetstart': 33,
'offsetend': 37,
'id': 'c_8421'}]
Thank you so much for any help!