zoukankan      html  css  js  c++  java
  • 中文词频统计

    import jieba
    
    f = open('article.txt','r',encoding='utf-8')
    text = f.read()
    f.close()
    stri = '''一!“”,。?;’"',.、:
    '''
    for s in stri:
        text = text.replace(s,' ')
    wordlist = list(jieba.cut(text))
    exclude = {'','你们','','','','','','','','他们','','','','','','','',
               '','','可是','自己','','','什么','','一个',' ','','','','一点','','',
               '没有','','','','','','','','','不是','','但是','已经','那么','','因为',}
    set = set(wordlist) - exclude
    dict = {}
    for key in set:
        dict[key]=wordlist.count(key)
    dictlist = list(dict.items())
    dictlist.sort(key=lambda x: x[1], reverse=True)
    f1 = open('articleCount.txt', 'a',encoding='utf-8')
    for i in  range(20):
        f1.write(str(dictlist[i])+'
    ')
        print(dictlist[i])
    f1.close()

    结果截图:

  • 相关阅读:
    L2-1 功夫传人 (25分)
    7-11 家庭房产(25 分)
    7-11 玩转二叉树 (25分)
    7-10 排座位 (25分)
    7-12 最长对称子串 (25分)
    7-10 树的遍历 (25分)
    STL
    Max Gcd
    水果
    Rails
  • 原文地址:https://www.cnblogs.com/stcy520/p/8665174.html
Copyright © 2011-2022 走看看