Question: The following program in PYTHON is designed to count the frequencies of words in a text le. The program creates a dictionary in which the
The following program in PYTHON is designed to count the frequencies of words in a text le. The program creates a dictionary in which the keys are the individual words found in the le and the values are the number of times each word appears. For example, if the word the appears 128 times, the dictionary would contain an element with 'the' as the key and 128 as the value. The program displays the frequency of each word. Please complete the program.
def main ():
fileName = " text .txt"
dict = wordCount ( fileName )
display ( dict )
def wordCount ( fileName ):
dict ={}
# This function should open a file by given file name .
# Read lines into program , split each line into words
# Read word and their counts in a dictionary return dict
# return the dictionary contains the data
def display ( dict ):
# You need to use loop to print out each word and their frequency
main ()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
