On Dec 20, 2018 12:17 PM, "Mary Sauerland" <msauerland...@gmail.com> wrote: > > Hi, > > I want to get rid of words that are less than three characters but I keep getting errors. I tried multiple ways but keep getting errors.
Hi Mary welcome to the tutor list. We love to help. We are a few volunteers. It is very difficult for us to be mind readers. So please give us more information. Especially what the error is you are getting. I presume it is what we call a trace back. It is important that you copy the entire traceback and paste it into the email. It will also be very helpful if you gave us a sample of the two text files and the output You're Expecting. > > Here is my code: > > f1_name = "/Users/marysauerland/Documents/file1.txt" > #the opinions > f2_name = "/Users/marysauerland/Documents/file2.txt" > #the constitution > > > def read_words(words_file): > return [word.upper() for line in open(words_file, 'r') for word in line.split()] > > > read_words(f1_name) > #performs the function on the file > set1 = set(read_words(f1_name)) > #makes each word into a set and removes duplicate words > read_words(f2_name) > set2 = set(read_words(f2_name)) > > count_same_words = 0 > > for word in set1: > if word in set2: > count_same_words += 1 > #comparing the set1 (set of unique words in the opinions) with set2 (set of unique words in the constitution) and adding 1 for each matching word found which is just counting the words > print(count_same_words) > > > Best, > > Mary > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor