Question: Use Python 2 Please! Create a class called wordCounter which uses a default init_ method, which takes no arguments (except self). The wordCounter clas no

Use Python 2 Please!
Create a class called wordCounter which uses a default init_ method, which takes no arguments (except self). The wordCounter clas no class variables and has the following attributes, with initial values self.wordFrequency. 0 #empty dictionary In addition to the default_init_method, the wordCounter class should have the following methods: 1) def count_words(self, filename) : This method takes in one parameter that is the filename containing words(in addition to self). The method should read the file line by line and add the words in each line as keys to the dictionary, with the values representing the number c times the word has been seen so far. The function should first check to see if the word exists as a key in the dictionary. If the word is in the dictionary, then you should increment its count by one. If the word is not in the dictionary, then the function should add the word to the dictionary as a key, with a corresponding value 1, as an integer. For example, if the file contents are as follows: "this is a sentence" this is a group of words" The contents of wordFrequency would look like, "this".2, "is":2, "a":2, "sentence":1, "group":1, "words":1) NOTE1: Wrap your file open function with a try-except block. If the file open fails, return None NOTE2: Make sure to strip any leading or trailing characters from the words 2) Write a function lookup. This method accepts one parameter i.e. the word to lookup from the dictionary. It checks if the word exists in wordFrequency and returns the frequency of the word otherwise it returns None
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
