import os
import re
import sys
sys.stdout=open('f1.txt','w')
from collections import Counter
from glob import glob
def removegarbage(text):
text=re.sub(r'\W+',' ',text)
text=text.lower()
return text
folderpath='d:/induvidual-articles'
counter=Counter()
filepaths = glob(os.path.join(folderpath,'*.txt'))
num_files = len(filepaths)
with open('topics.txt','r') as filehandle:
lines = filehandle.read()
words = removegarbage(lines).split()
counter.update(words)
for word, count in counter.most_common():
probability=count//num_files
print('{} {} {}'.format(word,count,probability))
i am getting a zero division error:float division by zero
for the line
probability=count//num_files
how do i rectify it?
i need my output to be of the form:
word, count ,probability
Plz help!