# Get the distinct words in the order of their first appearance
distinct_words = list(dict.fromkeys(words))
def remove_duplicates(data):
# For list type
if isinstance(data, list):
seen = set()
result = []
for item in data:
if item not in seen:
result.append(item)
seen.add(item)
return result # Return as list
# For tuple type
elif isinstance(data, tuple):
seen = set()
result = []
for item in data:
if item not in seen:
result.append(item)
seen.add(item)
return tuple(result) # Return as tuple
# For set type
elif isinstance(data, set):
return list(data) # Return as list (or tuple if needed)
# For string type
elif isinstance(data, str):
seen = set()
result = []
for char in data:
if char not in seen:
result.append(char)
seen.add(char)
return ''.join(result) # Return as string
# For unsupported types, return the data as is (like integers)
return data
# Example usage:
# For a list
input_list = [1, 2, 2, 3, 4, 4, 5]
print(remove_duplicates(input_list)) # Output: [1, 2, 3, 4, 5]
# For a tuple
input_tuple = (1, 2, 2, 3, 4, 4, 5)
print(remove_duplicates(input_tuple)) # Output: (1, 2, 3, 4, 5)
# For a set
input_set = {1, 2, 2, 3, 4, 4, 5}
print(remove_duplicates(input_set)) # Output: [1, 2, 3, 4, 5]
# For a string
input_string = "abcabcdeabc"
print(remove_duplicates(input_string)) # Output: "abcde"