综合练习:词频统计

fo =open("jj.txt","r")
news=fo.read()
fo.close

sep='''",.!?:'''
exclude={'the','she','you','it','a','and','is','in','so'}
for i in sep:
    news= news.replace(i," ")

wordList=news.lower().split()
wordDict={}
wordSet= set(wordList)-exclude

for c in wordSet:
    wordDict[c]=wordList.count(c)

'''for c in wordDict:
    print(c,wordDict[c])'''

dictList= list(wordDict.items())
dictList.sort(key=lambda x:x[1],reverse=True)

for w in range(20):
    print(dictList[w])

  

 

posted @ 2018-03-26 11:15  086刘伟锋  阅读(86)  评论(0编辑  收藏  举报