dotsfile = open('dots.txt', 'r') wantedfile = open('wanted.txt', 'r') keywordsfile = open('keywords.txt', 'w') instructionsfile = open('instructions.txt', 'r') def commandStrip(sentence): for line in dotsfile: sentence = sentence.replace(line.strip('\n'), '') return sentence def searchKeyWords(sentence): found = [] for line in wantedfile: if sentence.find(line.strip('\n')) >= 0: found.append(line.strip('\n')) return found def saveKeyWords(array): for line in array: if line != '': keywordsfile.write(line + '\n') saveKeyWords(searchKeyWords(commandStrip(instructionsfile.read()))) dotsfile.close() wantedfile.close() keywordsfile.close() instructionsfile.close()