I have list of dicts where sometime there are duplicate dict. For ex:
objList =
[{
'Name': 'plate',
'StartTime': '2022-05-17T10:26:05.738101',
}, {
'Name': 'bezel',
'StartTime': '2022-05-17T10:26:09.922667',
}, {
'Name': 'chrome',
'StartTime': '2022-05-17T10:26:23.283304',
}, {
'Name': 'plate placement',
'StartTime': '2022-05-17T10:26:25.570845',
}, {
'Name': 'plate placement',
'StartTime': '2022-05-17T10:26:39.3390',
}]
In above data, plate placement is duplicated. Similarly, any dict can be duplicated but I have delete any of the duplicate data and just keep one. For this, first I thought of checking if in the list we have duplicate dicts or not:
obj_names = []
for obj in objList:
obj_names.append(obj['Name'])
Now obj_names contains ['plate', 'bezel', 'chrome', 'plate placement', 'plate placement']. So this way we know that which dict is duplicated. We now have to delete any one of its occurrences. How can we delete that occurrence from the list?