Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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, valStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started