I just broke my rules about not adding more than one program in one language, but this code has gotta go in: contribution by Peter Norvig via email. Thank you!

This commit is contained in:
Crista Lopes
2013-10-07 14:57:15 -07:00
parent 42019f8f44
commit 872eabffdb

10
04-code-golf/tf-04-pn.py Normal file
View File

@@ -0,0 +1,10 @@
# My golf score is slightly lower!
# Best wishes, Peter Norvig
import re, sys, collections
stopwords = set(open('../stop_words.txt').read().split(','))
words = re.findall('[a-z]{2,}', open(sys.argv[1]).read().lower())
counts = collections.Counter(w for w in words if w not in stopwords)
for (w, c) in counts.most_common(25):
print w, '-', c