70. Problem to remove duplicate dictionaries from a list.

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
  1. Take a list of dictionaries as input.
  2. Create an empty list.
  3. Check whether each element in the given list is unique or not using for loop and an if statement.
  4. If it is unique then add it to the empty list.
  5. 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

Check whether a specified list is sorted or not

Elements are unique or not from the given list

Leave a Comment