I'm a little stuck on this particular piece of code that I'm working on. I'm supposed to check the contents of 1 text file (original), and compare it with another text file (filter) to see if there's any words that matches up.
What I have now is a so-called working comparison piece of code, as the code is only able to detect the last word in the original to see if it's similar to the one that is on the filter. What puzzles is the fact that I've got several of the similar words before the last word, but the code does not detect it as a similar text to the one that is on the filter.
Here's what I have now...
def open_file(): f = open("c:/temp/test.txt","r") g = open("c:/temp/filter.txt","r") line = f.readlines() line2 = g.readlines() array_size = 0 for loop in line: if line[array_size] == line2: print 'OFFENSIVE' print line[array_size] if line[array_size] != line2: print 'NOT OFFENSIVE' print line[array_size] array_size+=1 g.close() f.close() open_file()
If it helps, here's the original text:
filter lol filter lol lol filter lol
The text that is supposed to be filter is: "filter".
Any help would be greatly appreciated.