看板 Python 關於我們 聯絡資訊
※ 引述《isong (船沒開啊...)》之銘言: : 最近在練習讀檔的問題 : 假如我有一個檔 "text.txt" : 內容是: : on one of the ossuaries -- "Mariamene" -- offers. : that the tomb is That of : 我寫了一個程式 [deleted] : 請問我有辦法知道文章內有幾個字嗎 : (不包含'--'大小寫也算同一字如: That =that) : (有特殊符號就去掉,如"Mariamene"=Mariamene去掉雙引號 : offset.=offset去掉句點) [deleted] 來個短的 import re words = set([ word.lower() for word in re.findall(r"\w+", open("rf.dat").read()) ]) print len(words), "words in rf.dat counted as following:", words -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.139.129.184