Remove Duplicate Elements From a List in Python Using numpy

Python Program to Remove Duplicate Elements From a List Using numpy

# Remove Duplicate Element From a List Using numpy unique method in Python

# initializing list
test_list = [1, 5, 3, 9, 8, 5, 2, 3, 1]
print ("The original list is : " + str(test_list))
  
# using numpy
import numpy as np
  
# Removing duplicated from list
res = np.unique(test_list)
  
# printing list after removal
print ("The list after removing duplicates : " + str(res))

Output:

The original list is : [1, 5, 3, 9, 8, 5, 2, 3, 1]
The list after removing duplicates : [1 2 3 5 8 9]

About The Author

Leave a Reply