import word_countif__name__=="__main__":with (open("moby_01.txt") as infile,open("moby_01_clean.txt", "w") as outfile):for line in infile: cleaned_line = word_count.clean_line(line) cleaned_words = word_count.get_words(cleaned_line)# write all words for line outfile.write(cleaned_words) moby_words = []withopen('moby_01_clean.txt') as infile:for word in infile:if word.strip(): moby_words.append(word.strip()) word_counter = word_count.count_words(moby_words) most, least = word_count.word_stats(word_counter)print("Most common words:")for word in most:print(word)print("\nLeast common words:")for word in least:print(word)
Most common words:
('the', 14)
('i', 9)
('and', 9)
('of', 8)
('is', 7)
Least common words:
('call', 1)
('ishmael', 1)
('years', 1)
('ago', 1)
('never', 1)