Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedI 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

The Nature of Nonverbal Communication

Answered: 1 week ago

Question

Functions of Nonverbal Communication

Answered: 1 week ago

Question

Nonverbal Communication Codes

Answered: 1 week ago