Here is what I got. It is not working when I run it. Can someone help guide me on what is wrong with my code?
def unique_words(text : str) ->list:
text = open(text, 'r')
text_contents = text.read()
text.close()
word_list = text_contents.split()
word = open(str, 'w')
unique = []
for word in word_list:
if word not in word_list:
file.append(str(word) + "\n")
unique.sort()
return(unique)
Set will hold all unique values. If you add duplicate, then the set will ignore it.
word_list = ['hello', 'hello', 'world', 'world']
unique = set()
for word in word_list:
if word not in unique:
unique.add(word)
print(unique)