Design a function to output a list of all unique words in a string.

Design a function that takes in a string and outputs a list of all the unique words in the string.

Problem

Design a function that takes in a string and outputs a list of all the unique words in the string. 
Example input: "I am unique"
Example output: ["I", "am", "unique"]

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
def unique_words(string):
    
    This function takes in a string and outputs a list of all the unique words in the string.
    
    # split the string into a list of words
    words = string.split()
    # create a set of unique words
    unique_words = set(words)
    # convert the set to a list
    unique_words = list(unique_words)
    # return the list
    return unique_words

# test the function
print(unique_words("I am unique"))
print(unique_words("I am unique I am unique"))
print(unique_words("I am unique I am unique I am unique"))



This solution is optimal because it uses a set to create a list of unique words.


A.I. Evaluation of the Solution

This solution is correct and uses an efficient approach.

Evaluated at: 2022-11-20 10:16:26