Filter a list of dictionaries to remove duplicates within a key, based on another key
问题 I have a list of dictionaries in Python 3.5.2 that I am attempting to "deduplicate". All of the dictionaries are unique, but there is a specific key I would like to deduplicate on, keeping the dictionary with the most non-null values. For example, I have the following list of dictionaries: d1 = {"id":"a", "foo":"bar", "baz":"bat"} d2 = {"id":"b", "foo":"bar", "baz":None} d3 = {"id":"a", "foo":"bar", "baz":None} d4 = {"id":"b", "foo":"bar", "baz":"bat"} l = [d1, d2, d3, d4] I would like to