How to check if sentence contains words only from a file
I am trying to create a program that checks if a string entered by the user contains only words from a text file, which will contain all words from the English dictionary. This will remove any slang language. If you have any other way of doing this, please let me know as I am relatively new to python.
Thanks in advance.
#Opening the Dictionary textfile which contain all dictionary words except slangs.
#Reading the whole dictionary as a text.
#Getting the sentence from the User.
user_sentence=raw_input("Give me the sentence!")
#Spliting User sentence into word so that check for slang and remove it.
slang_removed_splited_user_sentence=[word for word in splited_user_sentence if word in alltext_from_dictionary ]
print "Here is the slang removed sentence"
Call it like: slang_remover("dictionary.txt")
Asked in February 2016Viewed 3,647 timesVoted 10Answered 3 times