Let's say I have a list of dictionaries:
[
{'id': 1, 'name': 'john', 'age': 34},
{'id': 1, 'name': 'john', 'age': 34},
{'id': 2, 'name': 'hanna', 'age': 30},
]
How can I obtain a list of unique dictionaries (removing the duplicates)?
[
{'id': 1, 'name': 'john', 'age': 34},
{'id': 2, 'name': 'hanna', 'age': 30},
]
See How can I properly hash dictionaries with a common set of keys, for deduplication purposes? for in-depth, technical discussion of why the usual approach for deduplicating a list (explained at Removing duplicates in lists) does not work.
set(frozenset(i.items()) for i in list)
– Syngamy