Python: Remove Duplicates Array

In Python, you can use set() or list comprehension to remove duplicate elements from a one-dimensional array.

Option 1: Approach 1: Utilize the set() method.

arr = [1, 2, 3, 1, 2, 3, 4]
unique_arr = list(set(arr))
print(unique_arr)

Option 1: Method 2: Utilizing list comprehensions.

arr = [1, 2, 3, 1, 2, 3, 4]
unique_arr = list(dict.fromkeys(arr))
print(unique_arr)
bannerAds