I have the following dictionary list
dict_list = [{"feed_id": 101, "query_id": 201, "bind_id": 301, "qname":"q1"},
{"feed_id": 101, "query_id": 201, "bind_id": 301, "qname":"q2"},
{"feed_id": 103, "query_id": 201, "bind_id": 301, "qname":"q1"},
{"feed_id": 103, "query_id": 202, "bind_id": 301, "qname":"q3"},
{"feed_id": 103, "bind_id": 301, "bname": "b1"},
{"feed_id": 101, "query_id": 201, "qname":"q1"}]
I want to remove duplicates based on the combination of three keys. The result list should look like
result_dict_list = [{"feed_id": 101, "query_id": 201, "bind_id": 301, "qname":"q1"},
{"feed_id": 103, "query_id": 201, "bind_id": 301, "qname":"q1"},
{"feed_id": 103, "query_id": 202, "bind_id": 301, "qname":"q3"},
{"feed_id": 103, "bind_id": 301, "bname": "b1"},
{"feed_id": 101, "query_id": 201, "qname":"q1"}]
These are the requirements in terms of object structure
feed_id
will exist for all objects and cannot be nullquery_id
andbind_id
are optional. If even one of the property does not exist, no need to check whether the object is duplicate- All three properties values are numbers. If the key exist, value cannot be null.
- There can be many other properties in each object but to eliminate duplicates we care only about
feed_id, query_id and bind_id
- Order of the list doesn't matter
What would be the most efficient way to remove duplicates from the list in python?
Thanks