Need help with Python assignment (word counter):
I need to write a program that counts how many times each word appears in a text file.
Weโre given a function countFile(fname) that reads the file line by line and calls my function countWords(counts, line).
they provide function as following
def countFile(fname): counts={} with open(fname) as f: for line in f: countWords(counts,line) pass pass printResults(counts) pass
Tasks:
Implement countWords(counts, line)
Split each line into words
Update a dictionary that tracks word frequencies
Improve accuracy by:
Removing punctuation using strip('-?.!,[]โ:;"'')
Making all words lowercase using .lower()
Modify printResults() to print:
One word and its count per line (e.g. the : 72)
Sort the output alphabetically by word before printing.
If anyone can help with the logic or sample code, Iโd really appreciate it ๐
