Question: Part A . Write a function wordDictFromFile ( ) that processes a file and aggregates word counts into a dictionary. The function takes a filename

Part A. Write a function wordDictFromFile() that processes a file and aggregates word counts into a dictionary. The function takes a filename parameter:
filename, an input file containing multiple lines in the format
word:count word:count ...
where word is a string and count is an integer. The function returns a dictionary of key: value pairs, where each key is a word from the file and its corresponding value is the total count for that word.
For example, if an existing input file, input.txt, contains:
it:3 is:2 fun:12 what:1
python:1 is:1 fun:3
print(wordDictFromFile('input.txt')) will display
{'it':3,'is': 3, 'fun': 15, 'what': 1, 'python': 1}
Part B. Given the existing file input.txt and a target count =5. Write code that utilizes the
wordDictFromFile () function to produce and print on the screen the list of distinct words with a total word count no more than target. The output for the given example would be ['it','is', 'what ', 'python']
Edit Format Table
12pt vv Paragraph
Part A . Write a function wordDictFromFile ( )

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 Programming Questions!