You realize that this function is implementing a poor Set? Use a dictionary with unit values instead.