python运用:统计单词词频

#统计单词词频
path = "词频统计.txt"
with open(path,"r",encoding = "utf-8") as f1:
    with open("统计结果","w",encoding = "utf-8") as f2:
        words = f1.read().split()
        for word in words:
            word = word.strip(".")
            word = word.strip(",")
            content = "{}:{}次\n".format(word,words.count(word))
            f2.write(content)
    print()

你可能感兴趣的:(python,开发语言,后端)