a guest Apr 21st, 2009 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- from string import letters
- def frequent_words(filename, n):
- wordlist = filter(len, [filter(lambda chr: chr in letters, word.lower()) for word in open(filename).read().split()])
- counts = dict((word, wordlist.count(word)) for word in wordlist)
- return [(word, counts[word]) for word in sorted(counts, key=lambda word: counts[word], reverse=True)][:n]
RAW Paste Data