You are here

Most common words

8 September, 2015 - 10:43

To find the most common words, we can apply the DSU pattern; most_common takes a histogram and returns a list of word-frequency tuples, sorted in reverse order by frequency:

def most_common(hist):
t = []
for key, value in hist.items():
t.append((value, key))
return t

Here is a loop that prints the ten most common words:

t = most_common(hist)print 'The most common words are:'for freq, word in t[0:10]:print word, '\t', freq

And here are the results from Emma:

The most common words are:to 5242the 5205and 4897of 4295i 3191a 3130it 2529her 2483was 2400she 2364