How to return unique words from the text file using Python
问题 How do I return all the unique words from a text file using Python? For example: I am not a robot I am a human Should return: I am not a robot human Here is what I've done so far: def unique_file(input_filename, output_filename): input_file = open(input_filename, 'r') file_contents = input_file.read() input_file.close() word_list = file_contents.split() file = open(output_filename, 'w') for word in word_list: if word not in word_list: file.write(str(word) + "\n") file.close() The text file