myData = [ {'a': 1}, {'a': 1}, {'b': 1}, {'b': 1}, {'c': 1}, {'c': 1}, ] # Use a set to track seen tuples of items (key-value pairs as tuples) seen = set() unique_data = [] for d in myData: # Convert each dictionary to a tuple of its items, then convert to frozenset # to make it hashable and suitable for use in a set dict_items = frozenset(d.items()) # Check if the frozenset of items is already in the set if dict_items not in seen: # If not seen, add to both set and result list seen.add(dict_items) unique_data.append(d) print(unique_data)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter