xxxxxxxxxx
original = ['a', 'b', 'a']
non_duplicates = list(set(original))
print(non_duplicates)
xxxxxxxxxx
# Approach 1: Using set
original_list = [1, 2, 3, 2, 4, 5, 1, 3, 3, 4, 5]
unique_list = list(set(original_list))
print(unique_list)
# Approach 2: Using a loop
original_list = [1, 2, 3, 2, 4, 5, 1, 3, 3, 4, 5]
unique_list = []
for element in original_list:
if element not in unique_list:
unique_list.append(element)
print(unique_list)
xxxxxxxxxx
# Method 1 = convert to set to remove duplicate and then convert back to list
mylist = list(set(mylist))
# Method 2 = use numpy to convert list to array and the apply unique method
np.unique(np.array(mylist)) # You can change the array back to list
# Method 3 = For pandas dataframe
df["col"].unique()