Hello I have bulk of list of dict and would like to remove duplicate dict and value with None. Within the data structure, bunch dict are duplicate. I want to keep pair of devices.
BulkData
[
{"name": "PAIR-05|PAIR-06", "device": "oob-01"},
{"name": "PAIR-05|PAIR-06", "device": "oob-01"},
{"name": "PAIR-01|PAIR-02", "device": "oob-03"},
{"name": "PAIR-01|PAIR-02", "device": "oob-03"},
{"name": None, "device": "oob-01"},
{"name": None, "device": "oob-01"},
{"name": None, "device": "oob-01"},
{"name": None, "device": "oob-01"},
]
Non-working code:
for key, value in bulkpairdata.items():
t = []
if bulkpairdata.get("name") != None:
if bulkpairdata.get("name") not in t:
result.append(bulkpairdata)
t.append(bulkpairdata.get("name"))
else:
bulkpairdata.remove(bulkpairdata.get("name"))
Result:
[
{"name": "PAIR-05|PAIR-06", "device": "oob-01"},
{"name": "PAIR-01|PAIR-02", "device": "oob-03"},
]
You can try something like this:
which yields following result: