Skip to content
Advertisement

Remove duplicate JSON objects from list in python

I have a list of dict where a particular value is repeated multiple times, and I would like to remove the duplicate values.

My list:

JavaScript

function to remove duplicate values:

JavaScript

When I call this function I get generator object.

JavaScript

When I try to iterate over the generator I get TypeError: unhashable type: 'dict'

Is there a way to remove the duplicate values or to iterate over the generator

Advertisement

Answer

You can easily remove duplicate keys by dictionary comprehension, since dictionary does not allow duplicate keys, as below-

JavaScript

Output-

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement