Advertisement
Guest User

g

a guest
Apr 21st, 2009
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. from string import letters
  2.  
  3. def frequent_words(filename, n):
  4.     wordlist = filter(len, [filter(lambda chr: chr in letters, word.lower()) for word in open(filename).read().split()])
  5.     counts = dict((word, wordlist.count(word)) for word in wordlist)
  6.     return [(word, counts[word]) for word in sorted(counts, key=lambda word: counts[word], reverse=True)][:n]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement