Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: Create a function named add_item that takes two parameters, the dictionary being used and the word to lookup (in that order). If the

Part 1:

Create a function named add_item that takes two parameters, the dictionary being used and the word to lookup (in that order).

  • If the word is NOT in the dictionary add it with a count of 1

  • If the word is in the dictionary, update the count accordingly

  • Return the current count (after the add) for the word

Create a function named build_dictionary that takes a list of words (as a parameter) and returns a dictionary that contains a count for each word from the list of words. The function build_dictionary will call add_item for every value in the list.

After you are done, the following should work:

sentence = "the quick brown fox jumped over the dog"

words = sentence.split()
d = build_dictionary(words)
# should be True 

print(d["the"] == 2)

print(d["dog"] == sentence.count("dog"))

If you need a refresher on split or count (see the lesson on strings)

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

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions