religion_project.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:religion_project 作者: 000384832 项目源码 文件源码
def occurencecount():

    # Ask the user to input a word
    word = raw_input("Enter a word : ")

    # Create a list of file which we will be looking into for matches
    fileList = ['Text1.txt', 'Text2.txt', 'Text3.txt', 'Text4.txt']

    # Open the files one by one, read them and find the occurance count inside each file
    for filename in fileList:

        # Openthe file
        fp_text = codecs.open(filename, 'r', 'utf-8')

        # Read all the words inside the file
        words_text = word_tokenize(fp_text.read())

        # Find the number of occurances of each word using built in method from NLTK
        fd_text = FreqDist(words_text)

        # Print out the number of occurances for that specific word
        print("Number of occurences in " + filename + " :  " + str(fd_text[word]))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号