I have json that looks like this
{"k2": 39, "k1": 52}
{"k2": 39, "k1": 52}
{"k3": 66, "k2": 38}
{"k2": 35}
{}
{}
{"k1": 52, "k2": 39}
I need to delete all duplicated dicts from this json
I was trying to use set comprehension with tuple but it doesnt work i’ve got an error
'str' object has no attribute 'items'
code.py
import json
a = open('aboba.json', 'r')
data = a.read()
get_json = json.loads(json.dumps(data))
delete_all_dublicates = [dict(t) for t in {tuple(d.items()) for d in get_json}]
print(delete_all_dublicates)
2
Answers
If I understood you correct, by provided steps you can remove duplicates:
This is my answer using the operator **: