Remove duplicates from a list AND keep the original order of the elements
You have a list of elements. You want to remove the duplicates but you want to keep the original order of the elements too. Example:
input: apple, fruit, dog, fruit, cat, apple, dog, cat
output: apple, fruit, dog, cat
def remove_duplicates(li): my_set = set() res =  for e in li: if e not in my_set: res.append(e) my_set.add(e) # return res
list(set(li)) is not acceptable in this case because elements are unordered in a set.