Inspired from the
Counter
collection that you use:from glob import glob
from collections import Counter
import re
folderpaths = 'd:/individual-articles'
counter = Counter()
filepaths = glob(os.path.join(folderpaths,'*.txt'))
for file in filepaths:
with open(file) as f:
words = re.findall(r'\w+', f.read().lower())
counter = counter + Counter(words)
print counter
from : https://stackoverflow.com/questions/17399535/to-count-the-word-frequency-in-multiple-documents-python
No comments:
Post a Comment