How to return unique words from the text file using Python

后端 未结 9 2177
遇见更好的自我
遇见更好的自我 2021-01-04 23:45

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:

9条回答
  •  萌比男神i
    2021-01-05 00:01

    string = "I am not a robot\n I am a human"
    list_str = string.split()
    print list(set(list_str))
    

提交回复
热议问题