Answer:
See explaination
Explanation:
#function to count number of characters, words in a given file and returns a list of words
def GetGoing(filename):
file = open(filename)
numbrOfCharacters =0
numberOfWords = 0
WordList = []
#iterate over file line by line
for line in file:
#split the line into words
words = line.strip().split()
#add counn of words to numberOfWords
numberOfWords = numberOfWords + len(words)
#find number of characters in each word and add it to numbrOfCharacters
numbrOfCharacters = numbrOfCharacters + sum(len(word) for word in words)
#append each word from a line to WordList
for word in words:
WordList.append(word)
#display the result
print("The number of characters: ", numbrOfCharacters)
print("The number of Words: ", numberOfWords)
#return the list of words
return WordList
#find matches for keywords given in textlist
def FindMatches(keywordlist, textlist):
for keyword in keywordlist:
keyword = keyword.lower()
print ("The number of occurrences of {} is: {}".format(keyword,len([i for i, s in enumerate(textlist) if s == keyword])))
#main
booktext = GetGoing("constitution.txt")
FindMatches (['War', 'Peace', 'Power'], booktext)