""" John Rachlin DS 2000: Intro to Programming with Data Date: Thu Oct 27 19:50:33 2022 File: climb.py Description: Analyze "The Hill We Climb" """ import dataproc as dp def count_words(words): """ Convert a list of words to a word count dictionary """ wordcount = {} for word in words: if word in wordcount: wordcount[word] += 1 else: wordcount[word] = 1 return wordcount def main(): text = dp.read_text('the_hill_we_climb.txt') #print(text, len(text)) words = dp.text_to_words(text) #print(words) # Find 10 most common words wc = count_words(words) kv = list(wc.items()) kv.sort(key=lambda t: t[1], reverse=True) print(kv[:10]) # Does it surprise you that the most common word is 'we'? # Why might that be for a poem read at a presidential inaugeral? if __name__ == '__main__': main()