Files
exercises-in-programming-style/19-plugins/plugins-src/frequencies1.py
2013-10-18 16:59:09 -07:00

19 lines
470 B
Python

import operator
def top25(word_list):
"""
Takes a list of words and returns a dictionary associating
words with frequencies of occurrence
"""
if type(word_list) is not list or word_list == []:
return {}
word_freqs = {}
for w in word_list:
if w in word_freqs:
word_freqs[w] += 1
else:
word_freqs[w] = 1
return sorted(word_freqs.iteritems(), key=operator.itemgetter(1), reverse=True)[:25]