Sep-11-2019, 11:15 AM
Hi,
How can I create a script that reads two text files and prints out words that match within text file number 1?
This code below is the furthest I got, it can match words in string and print it out, but I need it to read two or more large text files and print same found matched words. Thank you.
How can I create a script that reads two text files and prints out words that match within text file number 1?
This code below is the furthest I got, it can match words in string and print it out, but I need it to read two or more large text files and print same found matched words. Thank you.
import re def get_words_from_string(s): return set(re.findall(re.compile('\w+'), s.lower())) def get_words_from_file(fname): with open(fname, 'rb') as inf: return get_words_from_string(inf.read()) def all_words(needle, haystack): return set(needle).issubset(set(haystack)) def any_words(needle, haystack): return set(needle).intersection(set(haystack)) search_words = get_words_from_string("this my test") find_in = get_words_from_string("If this were my test, I is passing") print (search_words)