diff --git a/04-code-golf/tf-04-pn.py b/04-code-golf/tf-04-pn.py new file mode 100644 index 0000000..87c6b3e --- /dev/null +++ b/04-code-golf/tf-04-pn.py @@ -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