Given List of dictionaries with list values, extract unique dictionaries.
Input : [{'Gfg': [2, 3], 'is' : [7, 8], 'best' : [10]}, {'Gfg': [2, 3], 'is' : [7, 8], 'best' : [10]}]
Output : [{'Gfg': [2, 3], 'is': [7, 8], 'best': [10]}]
Explanation : Both are similar dictionaries, and hence 1 is removed.
Input : [{'Gfg': [2, 3], 'is' : [7, 8], 'best' : [10]}, {'Gfg': [2, 3], 'is' : [7, 8], 'best' : [10, 11]}]
Output : [{'Gfg': [2, 3], 'is': [7, 8], 'best': [10]}, {'Gfg': [2, 3], 'is': [7, 8], 'best': [10, 11]}]
Explanation : None duplicate.
This is one of the ways in which this task can be performed. In this, we iterate for each dictionary and memoize it, and prevent it from adding to result.
OutputThe original list : [{'Gfg': [2, 3], 'is': [7, 8], 'best': [10]}, {'Gfg': [2, 3], 'is': [7], 'best': [10]}, {'Gfg': [2, 3], 'is': [7, 8], 'best': [10]}]
List after duplicates removal : [{'Gfg': [2, 3], 'is': [7, 8], 'best': [10]}, {'Gfg': [2, 3], 'is': [7], 'best': [10]}]
This is yet another way in which this task can be performed. In this, similar approach is employed as above, just the difference of encapsulating result in list comprehension for one-liner.
OutputThe original list : [{'Gfg': [2, 3], 'is': [7, 8], 'best': [10]}, {'Gfg': [2, 3], 'is': [7], 'best': [10]}, {'Gfg': [2, 3], 'is': [7, 8], 'best': [10]}]
List after duplicates removal : [{'Gfg': [2, 3], 'is': [7, 8], 'best': [10]}, {'Gfg': [2, 3], 'is': [7], 'best': [10]}]
OutputThe original list : [{'Gfg': (2, 3), 'is': (7, 8), 'best': (10,)}, {'Gfg': (2, 3), 'is': (7,), 'best': (10,)}, {'Gfg': (2, 3), 'is': (7, 8), 'best': (10,)}]
List after duplicates removal : [{'Gfg': (2, 3), 'is': (7, 8), 'best': (10,)}, {'Gfg': (2, 3), 'is': (7,), 'best': (10,)}]