Question: Write a program the uses a dictionary to create a histogram. Count the occurrences of each word in the file, Myra.txt . Be sure to

Write a program the uses a dictionary to create a histogram. Count the occurrences of each word in the
file, Myra.txt. Be sure to convert all letters to lower case so your results are not case sensitive. Finally,
have your program print out the contents of the dictionary. Download and use the following starter
files:
histogram.py
Myra.txt
Out on the Mira on warm afternoons
Old men go fishing with black line and spoons
And if they catch nothing they never complain
And I wish I was with them again
As boys in the boats call to girls on the shore
Teasing the ones that they dearly adore
And into the evening the courting begins
And I wish I was with them again
Can you imagine a piece of the universe
More fit for princes and kings
I'll trade you ten of your cities for Marion Bridge
And the pleasure it brings
Out on the Mira on soft summer nights
Bonfires blaze to the children's delight
They dance 'round the flames singing songs with their friends
And I wish I was with them again
And over the ashes the stories are told
of witches and werewolves and Oak Island gold
stars on the river face sparkle and spin
I wish I was with them again
Can you imagine a piece of the universe
More fit for princes and kings
I'll trade you ten of your cities for Marion Bridge
And the pleasure it brings
Out on the Mira the people are kind
They'll treat you to homebrew and help you unwind
And if you come broken they'll see that you mend
I wish I was with them again
Now I'll conclude with a wish you go well
Sweet be your dreams and your happiness swell
I'll leave you here for my journey begins
I'm going to be with them again ```
def histogram(fin):
hist = dict()
# Read every line in fin
for :
# Split() the line into a list of words
# Process every word in the list
for :
# Convert each word to lower case
# Check if each word is in the dictionary
if :
# If not, add it
else:
return hist
def printHistogram(hist):
print("Word Count")
print("----------------")
for word in hist:
print(f"{word:12}{hist[word]:2d}")
fin = open('Myra.txt')
print('Reading file Myra.txt...')
hist = histogram(fin)
printHistogram(hist)
```
Write a program the uses a dictionary to create a

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!