Modernize Python 2 code to get ready for Python 3
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
# My golf score is slightly lower!
|
||||
# Best wishes, Peter Norvig
|
||||
|
||||
from __future__ import print_function
|
||||
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
|
||||
print(w, '-', c)
|
||||
|
||||
Reference in New Issue
Block a user