Question: I have the following code that is counting the most used words in the text file. I need to only count the text after the

I have the following code that is counting the most used words in the text file. I need to only count the text after the word From, it is a file of email data and I only want to count the email addresses and return the most common email address and the count of the emails

I have the following code that is counting the most used wordsI need to edit it so that I am only counting strings that are after the word 'From' in a text file. Right now it's counting all words, but I just need the From email addresses in a text file. I think the issue if in the if/else loop but nothing I have tried works. Please help!

1 import string 2 fhand open('C: \Users \Brooke\Canopy scripts mbox-short.txt') 3 countsdict) 4 for line in fhand: 5line line.translate(None, string.punctuation) 6 line - line. lower 7 wordsline.split() for word in words: 9 if word not in counts counts[word] 1 else: counts[word] + 1 13 1st list) 14 for key, val in counts.items(): 15 1st.append ((val,key)) 161st, sort (reverse = True) 17 for key, val in lst[:10]: print key, val

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!