# Uses a Counter to implement a word count, # so that the user can see which words # occur the most in the book Moby-Dick. from collections import Counter # minimum number of occurrences needed to be printed OCCURRENCES = 2000 def intro(): print("This program displays the most") print("frequently occurring words from") print("the book Moby Dick.") print() # Displays all words in the dictionary that occur # at least OCCURRENCES number of times. def print_results(word_counts): for word, count in word_counts.items(): if count > OCCURRENCES: print(word, "occurs", count, "times.") def main(): intro() with open("mobydick.txt") as file: words = file.read().lower().split() word_counts = Counter(words) print_results(word_counts) main()