In this Python list program, we will take a user input as a list and remove duplicate dictionaries from a given list with the help of the below-given steps.
Remove duplicate dictionaries:
Steps to solve the program
- Take a list of dictionaries as input.
- Create an empty list.
- Check whether each element in the given list is unique or not using for loop and an if statement.
- If it is unique then add it to the empty list.
- Print the list to see the output i.e. list after we remove duplicate dictionaries from it.
#Input lists
list1 = [{"name": "john"}, {"city": "mumbai"}, {"Python": "laguage"}, {"name": "john"}]
list2 = []
for dic in list1:
if dic not in list2:
list2.append(dic)
#Printing output
print(list2)
Output :
[{'name': 'john'}, {'city': 'mumbai'}, {'Python': 'laguage'}]
Related Articles
Python program to check if the elements of a given list are unique or not.
Python program to remove duplicate sublists from the list.
Python program to create a list by taking an alternate item from the list.
Python program to remove duplicate tuples from the list.
Python program to insert an element before each element of a list.
Python program to remove the duplicate string from the list.