def word_frequency ( words ): # # Create an empty dictionary named 'counts' to store word frequencies. # counts = dict() # # Consider each word in the list. # for word in words: if word in counts: counts[word] = counts[word] + 1 else: counts[word] = 1 return counts def word_frequency_test ( ): words = [ 'A', 'sailor', 'went', 'to', 'sea', 'sea', 'sea', 'To', 'see', 'what', 'he', 'could', 'see', 'see', 'see', 'But', 'all', 'that', 'he', 'could', 'see', 'see', 'see', 'Was', 'the', 'bottom', 'of', 'the', 'deep', 'blue', 'sea', 'sea', 'sea' ] print ( '' ) print ( ' Word list:' ) print ( '' ) print ( words ) counts = word_frequency ( words ) print ( '' ) print ( ' Word frequency dictionary:' ) print ( '' ) print ( counts ) return if ( __name__ == "__main__" ): word_frequency_test ( )