#encoding=utf-8
"""
读一个文件,包含英文句子,请统计共多少个不重复的单词,
并且在另外一个文件中打印每个单词以及它的出线次数
"""
def noRepeat():
with open("E:\\murphy\\data\\1.txt","r",encoding="utf8") as fp:
words=""
writeContent={}
for line in fp:
for word in line:
if not word.isalpha():
word.replace(word," ")
words+=word
wordsList=words.split()
noRepeatWord=set(wordsList)
for i in noRepeatWord:
writeContent[i]=wordsList.count(i)
print(writeContent)
with open("E:\\murphy\\data\\norepeat.txt","w") as fp:
fp.write(str(writeContent))
print(noRepeat())