This is a Python Program to remove the duplicate items from a list.
The program takes a lists and removes the duplicate items from the list.
1. Take the number of elements in the list and store it in a variable.
2. Accept the values into the list using a for loop and insert them into the list.
3. Use a for loop to traverse through the elements of the list.
4. Use an if statement to check if the element is already there in the list and if it is not there, append it to another list.
5. Print the non-duplicate items of the list.
Here is source code of the Python Program to remove the duplicate items from a list. The program output is also shown below.
a= n= int(input("Enter the number of elements in list:")) for x in range(0,n): element=int(input("Enter element" + str(x+1) + ":")) a.append(element) b = set() unique =  for x in a: if x not in b: unique.append(x) b.add(x) print("Non-duplicate items:") print(unique)
1. User must enter the number of elements in the list and store it in a variable.
2. User must enter the values of elements into the list.
3. The append function obtains each element from the user and adds the same to the end of the list as many times as the number of elements taken.
4. The for loop basically traverses through the elements of the list and the if statement checks if the element is a duplicate or not.
5. If the element isn’t a duplicate, it is added into another list.
6. The list containing non-duplicate items is then displayed.
Case 1: Enter the number of elements in list:5 Enter element1:10 Enter element2:10 Enter element3:20 Enter element4:20 Enter element5:20 Non-duplicate items: [10, 20] Case 2: Enter the number of elements in list:7 Enter element1:10 Enter element2:20 Enter element3:20 Enter element4:30 Enter element5:40 Enter element6:40 Enter element7:50 Non-duplicate items: [10, 20, 30, 40, 50]
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.