I open a file using python to find whether a predefined set of words are present in the opened file or not. I took the predefined set of words in a list and opened the file
This code will show what words are present in the file, given that the word exactly matches, and is not preceded or followed by punctuation or other characters, and is of the same case. With some minor adjustment, the code could be made more forgiving.
words = set(['hello', 'world', 'testing'])
f = open('testfile.txt', 'rb')
data = set(f.read().split())
print words.intersection(data)