Answered step by step
Verified Expert Solution
Question
1 Approved Answer
8.5 LAB: Dictionary to count words - Python Write a full program that reads in a text file, and creates a dictionary to count how
8.5 LAB: Dictionary to count words - Python
Write a full program that reads in a text file, and creates a dictionary to count how often each word occurs in the file. You will need a nested for loop to find the count. Some code has been included for you. The ... means "to do" after the for, if, and else statements.
Ex: If the input is:
Enter the name of a file: mary.txt and the mary.txt file contains: Mary had a little lamb Whose fleece was white as snow. And everywhere that Mary went, The lamb was sure to go! the sorted output is: And: 1 Mary: 2 The: 1 Whose: 1 a: 1 as: 1 everywhere: 1 fleece: 1 go!: 1 had: 1 lamb: 2 little: 1 snow. : 1 sure: 1
Step 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