def word_count(self): with open(self.inputfile, "r") as string: string = string.read() list = re.split('\W+', string) my_dict = [str.lower(word) for word in list] numbers = Counter(my_dict).most_common(20) return numbers
def punct_count(self): with open(self.inputfile, "r") as string: string = string.read() my_dict = string.replace(" ", "").replace(" ", "").replace("\r\n", "").strip() list = re.split('\w+', my_dict) numbers = Counter(list).most_common(10) return numbers
def word_count(self): with open(self.inputfile, "r") as string: string = string.read() list = re.split('\W+', string) #https://docs.python.org/2/library/re.html ''' this took me forever to figure out and what to use since I previous got this wrong. this seems simple compared to previous attempted to break apart using string ''' ''' http://stackoverflow.com/questions/10134372/get-a-list-of-names-which-start-with-certain-letters First answer helped tell me how to put together a list comprehension. ''' my_dict = [str.lower(word) for word in list] numbers = Counter(my_dict).most_common(20) return numbers
def word_totalcount(self): with open(self.inputfile, "r") as string: string = string.read() counters = len(string.split()) print(counters)
def read_from_file(file_name): global original_file_name original_file_name = file_name with open(file_name, 'r') as string: string = string.read() return string