zoukankan      html  css  js  c++  java
  • 综合练习:词频统计

    fo=open('/Users/Administrator/Desktop/news.txt','r')
    news=fo.read()
    fo.close()
    sep=''',.?!";:--'''
    for i in sep:
        news=news.replace(i,' ').lower()
    news=news.split()
    
    word=dict(zip())
    
    for i in news:
        word[i]=news.count(i)
    
    words = '''
    a an the in on to at and of is was are were i he she you your they us their our it or for be too do no 
    that s so as but it's her we
    '''
    
    p= words.split()
    for i in p:
        if i in word.keys():
            del(word[i])
    
    word=sorted(word.items(),key=lambda x:x[1],reverse= True)
    
    
    for i in range(10):
        print(word[i])

  • 相关阅读:
    2017.11.20
    第8次
    作业 lianxi
    java 7个练习题
    java 2.15
    java 2.6
    jsp变量和方法的声明
    jsp 基本标签从头练习
    15
    14
  • 原文地址:https://www.cnblogs.com/129lai/p/8649632.html
Copyright © 2011-2022 走看看