View the step-by-step solution to:

Question

Write the function countWords(document), where document is the name of

txt file that contains multiple strings. This function returns (not prints) a dictionary whose keys are included words (in lowercase), and values their word counts. You can assume the string doesn't have any contraction words such as can't, don't, isn't, etc. The starter code already contains the code to read the txt file, just make sure the file is in the same directory as your .py file.

Hint: Remove punctuation and numbers before counting the words,

03.JPG

article.txt:

... He will be the president of the company; right now

he is a vice president.

... But he ..... himself, is no sure of it...

... (Later he will see the importance of these 3.)

03.JPG

Top Answer

def countWords ( document ): out = {} f = open(document) content = f.read() for word in... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question