/* ............... START ............... */
# Using a Set (Recommended for maintaining the order of the original list):
original_list = [1, 2, 2, 3, 4, 4, 5]
unique_list = list(set(original_list))
# Using a Loop (Preserves order):
original_list = [1, 2, 2, 3, 4, 4, 5]
unique_list = []
for item in original_list:
if item not in unique_list:
unique_list.append(item)
# Using List Comprehension (Preserves order):
original_list = [1, 2, 2, 3, 4, 4, 5]
unique_list = [x for i, x in enumerate(original_list) if x not in original_list[:i]]
/* ............... END ............... */
Remove all duplicates from list python #Fastest way to remove duplicates from list Python