Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import alic.txt and cound the number of words and characters in it. Count the number of words in the txt file and find the most

image text in transcribed
import alic.txt and cound the number of words and characters in it. Count the number of words in the txt file and find the most repeated one. In your program, first convert all words to lower case and then convert the first character to the upper case. Then do the analysi We are not interested in the following words: The, A, And, To, It Banwords= ['The', 'A', 'And', 'To', 'It'] filename = 'alice.txt' text = "?" (filename) " open the file print ('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: if word "?" in Banwords: \# the missing keyword let the loop continue if the word is not in the if word in counts: counts [word] = counts [word] +1 else: counts[word ]=1 MaxRep =0 Maxword =. for k,v in counts. " ?' (): \# we need both keys and values of the dictionary in the loop :-) if v> MaxRep: MaxRep =v Maxword =k print (Maxword,' is the most repeted word with ', MaxRep, 'times')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899