1

have a list of strings called my_list and I want to create a function called remove_duplicates that will take in this list as an argument and return a new list with all of the duplicates removed. The order of the elements in the original list should be preserved in the new list. For example, if my_list is ['a', 'b', 'c', 'b', 'd', 'a'], then the function should return a new list ['a', 'b', 'c', 'd'].

I have tried to solve this problem by using a for loop to iterate through my_list and adding each element to a new list called result if it is not already in result. However, this approach does not completely remove all of the duplicates. I am looking for a way to implement the remove_duplicates function in a way that will correctly remove all duplicates from the list.

dollahzing.blog

1 Answers1

1

You can use Set() it will remove all the duplicates example:

def remove_dup(list_temp:list)->list:
  return list(set(list_temp))

tomerar
  • 805
  • 5
  • 10