I have a class containing a list of strings. Say:
ClassName: - list_of_strings
I need to ensure that this list of strings contains unique elements. Unfortunately, I cannot change this list_of_strings to another type, for example, to a set.
In the addToList(str_to_add) function, I want to guarantee the uniqueness of the strings. How can i do this? Would it be advisable to add the line to be added to the list, convert to a set, then return to the list and then reassign it to the object?
Here I need to update the method:
def addToList(self, str_to_add): self.list_of_strings.append(str_to_add)
Thanks!
Cuga
source share