import re
import os
def fact(path):
dic = {}
fnames = os.listdir(path)
for fn in fnames:
filepath = os.path.join(path, fn)
txtnames=os.listdir(filepath)
for item in txtnames:
if re.search(r'\.txt$', item):
txtpath = os.path.join(filepath, item)
with open(txtpath, 'r', encoding='ISO-8859-15') as f:
s = f.read()
words = re.findall(r'[A-Za-z]{3,}', s)
for key in words:
key = key.lower()
dic[key] = dic.get(key, 0) + 1
return dic
# pass