[Solved]Python Count Frequency Word Text File Let User Choose Filename Read 1 Program Count Freque Q37154866
In python Count the frequency of each word in a text file. Letthe user choose a filename to read.
1. The program will count the frequency with which each wordappears in the text.
2. Words which are the spelled the same but differ by case willbe combined.
3. Punctuation should be removed
4. If the file does not exist, use a ‘try-execption’ block tohandle the error
5. Output will list the words alphabetically, with the word inthe first column and the count in the second column … i.e. as :1287
Psuedo Code
printWds(data)
## print each word in our data and the respective count
## but we need them sorted, dictionaries have a nice module,sorted
## and lists have sort. for x in sorted(data.keys()):
print() ## look at the formatting above
return
wordFreq(fptr)
## create empty data type, dictionary or list?
freq = {} or freq = []
## read in the first line
line = fptr.readline()
punctChars = (….create a tuple of punctuation characters toeliminate… )
while line:
for c in punctChars:
## use the string replace module to substitute an empty char
line = line.replace(c, “”)
## create a list of separate words that make up the string
words = line.split()
for each word in our split:
#create a temporary word converted to lower using thelower()
tmp = word.lower()
## add this to your database, this is where dictionaries havethe
## advantage over dictionaries … the get() method
freq[tmp] = freq.get(tmp, 0) + 1
read another line
return freq
Expert Answer
Answer to In python Count the frequency of each word in a text file. Let the user choose a filename to read. 1. The program will c… . . .
OR

