Write a python program to remove duplicates from a list that has multiple same elements. In this module, we are going to create a python program to remove the duplicate element from the list using the python predefine method that is set( )
Sample test 1
Input: a=[14,15,48,63,23,48,96,23,14]
Output: [14,15,48,63,23,96]
Sample test 2
Input: a=[“shiva”,”ram”,”ravi”,,”ram”,”som”,”shiva”]
Output: [“ram”,”ravi”,”som”,”shiva”]
Algorithm
- Take input how many element users want to add
- Append them to list
- Using the method to remove duplicate elements from it
- Printing the output
Python program to remove duplicate from a list
a=int(input("enter the size of list:")) lst=[] for i in range(a): b=input("element:") lst.append(b) print("original list",lst) asd=set(lst) print("new list",asd)
Explanation of the code
Step 1: take input from the user for how many elements want to be in a list
Step 2: creating a empty list to use further
Step 3: using the for loop take input and append in the list again and again
Step 4: now we print the list
Step 5: using the set( ) method to remove all duplicate elements from the list
Step 6: printing the list which has no duplicate elements
Output
In this module, we have seen how to remove the duplicate element from the list