def readfile(filename1,filename2):
fileinfo1=open(filename1,'r').readlines()
for i in fileinfo1:
wordlist1=i.split(' ')
fileinfo2=open(filename2,'r').readlines()
for i in fileinfo2:
wordlist2=i.split(' ')
for word in wordlist2:
wordlist1.append(word)
wordlist=wordlist1
return wordlist
def getstr(key,value):
countstr=key+'\t'+'<---->'+'\t'+str(value)
return countstr
if __name__=="__main__":
wordcnt={}
filename1='D:/fenci.txt'
filename2='D:/NOold2.txt'
wordlist=readfile(filename1,filename2)
wordlistall=wordlist
print(wordlistall)
print("Finish Reading File\n")
allwordnum=len(wordlistall)
print("Number of allwords is :")
print(allwordnum)
print("Start counting......")
这段操作后怎么可以找到该词频来源于哪个文件啊?
使用map来记录所有的单词 words = map()
1) words.append("word","file") 再遍历words来查找文件的来源
2) words.append(word,filearray),遍历words,在遍历filearray来查找文件的来源
麻烦问您一下,我可以直接在这个上面加代码吗?是不是源代码得修改?