因此,我一直在开发一个递归函数,该函数在仅.txt文件的python目录中循环,并且单词必须为4个字符长,并且忽略某些单词。我无法获取此以打印常用字词
import os
os.listdir("/Users/tylerjones/Downloads")
def walk(dirname,mydict):
for name in os.listdir(dirname):
path = os.path.join(dirname,name)
if os.path.isfile(path):
if (path.endswith(".txt")):
#listifyFile(path,mydict)
files.append(path)
else:
walk(path)
for line in walk:
line = line.translate(line.maketrans(' ',' ',string.punctuation))
ignore = ['the','a','if','in','it','of','or','on','and','to','because','ok','']
line = line.lower()
for word in line:
if (line in d) and len(word)==4:
d[word] = d[word] + 1
print(d)
else:
d[word] = 1
print(d)