import collections file = open("results.txt") # open and read file trump_list = [] trump = set(line.strip() for line in open('trump.txt')) # words that are inside sad.txt # in the future I should split words from punctuation, so Trump's count as Trump # for word in a.lower().split(): with open("results.txt") as f: for line in f: for word in line.split(): if word in trump: #print(word + " this is sad") trump_list.append(line + "
") break text_file = open("trump_news.htm", "w+") text_file.write("".join(trump_list)) # print("".join(happy_list)) # Close the file file.close()