Algorithm


  1. Create an empty list called unique_list to store unique elements.
  2. Iterate through each element, element, in the input list.
    • Check if the element is not already in unique_list.
      • If true, add the element to unique_list.
  3. After iterating through all elements in the input list, return the unique_list.
  4. The returned unique_list contains only the unique elements from the input list.

 

Code Examples

#1 Code Example- Python Program Using set()

Code - Python Programming

list_1 = [1, 2, 1, 4, 6]

print(list(set(list_1)))
Copy The Code & Try With Live Editor

Output

x
+
cmd
[1, 2, 4, 6]

#2 Code Example- Python Program Remove the items that are duplicated in two lists

Code - Python Programming

list_1 = [1, 2, 1, 4, 6]
list_2 = [7, 8, 2, 1]

print(list(set(list_1) ^ set(list_2)))
Copy The Code & Try With Live Editor

Output

x
+
cmd
[4, 6, 7, 8]
Advertisements

Demonstration


Python Programing Example to Remove Duplicate Element From a List-DevsEnv