国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

python統計文本字符串里單詞出現頻率的方法

來源:懂視網 責編:小采 時間:2020-11-27 14:33:46
文檔

python統計文本字符串里單詞出現頻率的方法

python統計文本字符串里單詞出現頻率的方法:本文實例講述了python統計文本字符串里單詞出現頻率的方法。分享給大家供大家參考。具體實現方法如下: # word frequency in a text # tested with Python24 vegaseat 25aug2005 # Chinese wisdom ... str1 = Man
推薦度:
導讀python統計文本字符串里單詞出現頻率的方法:本文實例講述了python統計文本字符串里單詞出現頻率的方法。分享給大家供大家參考。具體實現方法如下: # word frequency in a text # tested with Python24 vegaseat 25aug2005 # Chinese wisdom ... str1 = Man

本文實例講述了python統計文本字符串里單詞出現頻率的方法。分享給大家供大家參考。具體實現方法如下:

# word frequency in a text
# tested with Python24 vegaseat 25aug2005
# Chinese wisdom ...
str1 = """Man who run in front of car, get tired.
Man who run behind car, get exhausted."""
print "Original string:"
print str1
print
# create a list of words separated at whitespaces
wordList1 = str1.split(None)
# strip any punctuation marks and build modified word list
# start with an empty list
wordList2 = []
for word1 in wordList1:
 # last character of each word
 lastchar = word1[-1:]
 # use a list of punctuation marks
 if lastchar in [",", ".", "!", "?", ";"]:
 word2 = word1.rstrip(lastchar)
 else:
 word2 = word1
 # build a wordList of lower case modified words
 wordList2.append(word2.lower())
print "Word list created from modified string:"
print wordList2
print
# create a wordfrequency dictionary
# start with an empty dictionary
freqD2 = {}
for word2 in wordList2:
 freqD2[word2] = freqD2.get(word2, 0) + 1
# create a list of keys and sort the list
# all words are lower case already
keyList = freqD2.keys()
keyList.sort()
print "Frequency of each word in the word list (sorted):"
for key2 in keyList:
 print "%-10s %d" % (key2, freqD2[key2])

希望本文所述對大家的Python程序設計有所幫助。

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

python統計文本字符串里單詞出現頻率的方法

python統計文本字符串里單詞出現頻率的方法:本文實例講述了python統計文本字符串里單詞出現頻率的方法。分享給大家供大家參考。具體實現方法如下: # word frequency in a text # tested with Python24 vegaseat 25aug2005 # Chinese wisdom ... str1 = Man
推薦度:
標簽: 方法 統計 單詞
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 午夜高清在线观看免费完整版 | 欧美 国产 日韩 第一页 | 日韩亚洲视频 | 在线精品亚洲欧洲第一页 | 劲爆欧美第一页 | 亚洲精品制服丝袜二区 | 偷拍亚洲欧美 | 亚洲欧美在线观看 | 亚洲精品高清国产一久久 | 国产一区二区三区欧美精品 | 欧美一区二区在线免费观看 | 麻豆视频一区二区 | 国产高清在线免费视频 | 亚洲一区二区精品视频 | 亚洲一级毛片 | 久久久国产精品视频 | 久热精品视频 | 亚洲尹人九九大色香蕉网站 | 99精品视频在线观看免费 | 在线视频欧美日韩 | 国产亚洲欧美精品久久久 | 劲爆欧美精品13页 | 欧美亚洲日本国产 | 欧美日韩高清不卡免费观看 | 国精产品一区 | 国产一区二区三区免费在线观看 | 一区二区三区欧美日韩 | 国内一区亚洲综合图区欧美 | 国产手机在线国内精品 | 欧美亚洲国产一区 | 亚洲va欧美 | 在线免费黄色网址 | 国产日韩欧美另类重口在线观看 | 日韩精品在线第一页 | 国产69久久精品成人看小说 | 日韩成人在线观看视频 | 六月丁香网站 | 亚洲欧洲日产国码一级毛片 | 亚洲精品国产第七页在线 | 国产精品视频久久久久 | 国产91精品久久久久久 |