Menu
support@authoritypapers.com
+1(805) 568 7317

question 2 20 points import alic txt and cound the number of wordsand characters in 4944870

Question 2 (20 points): import
alic.txt and cound the number of wordsand characters in it. Count the number of words in the txt file and find the mostrepeated one. In your program, first convert all words to lower case and thenconvert the first character to the upper case. Then do theanalysis. We are not interested in the following words: The, A, And, To,It In [ ]: BanWords
=[‘The’, ‘A’,’And’, ‘To’,’It’] filename
= ‘alice.txt’text
= ‘?'(filename)
# open the fileprint(‘Please Wait, Counting the number of words..’)counts
= ‘?’
# create an empty dictionary the file
for line ‘?’ text:
# keyword in the for loop line
= line.’?'()
#convert to lower lettres. line
= line.’?'()
#convert the first letter to capital lettre. words
= line.’?'()
#spereate the words in the line based on whitespace
for word
in words: word
= word.rstrip(”’).,’s,’S,)”,)”,.,,,),:,’,””’) word
= word.lstrip(”'(,”,(“,”(”’)
if word “?”
in BanWords:
# the missing keyword let the loop continue if the word is not in the BanWords list.
if word
in counts: counts[word]
= counts[word]
+1
else: counts[word]
= 1MaxRep
= 0MaxWord
=
for k,v
in counts.’?'():
# we need both keys and values of the dictionary in the loop
if v
> MaxRep: MaxRep
= v MaxWord
= kprint (MaxWord,’ is the most repeted word with ‘,MaxRep,’times’) . . .

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now