看板 Python 關於我們 聯絡資訊
最近在練習讀檔的問題 假如我有一個檔 "text.txt" 內容是: on one of the ossuaries -- "Mariamene" -- offers. that the tomb is That of 我寫了一個程式 -------- import string i=open("text.txt","r") w=[] for line in i.readlines(): lineword=line.split() w.extend(lineword) w.sort() print w ----- 執行結果是 ['"Mariamene"', '--', '--', 'That', 'is', 'of', 'of', 'offers.' , 'on', 'one', 'ossuaries', 'that', 'the', 'the', 'tomb'] ----- 請問我有辦法知道文章內有幾個字嗎 (不包含'--'大小寫也算同一字如: That =that) (有特殊符號就去掉,如"Mariamene"=Mariamene去掉雙引號 offset.=offset去掉句點) 我想要輸出的結果為 ['is','mariamene', 'of', 'offers', 'on', 'one', 'ossuaries', 'that', 'tomb'] 這樣一共9個字 謝謝高手大哥能幫忙一下 想了很久都不知道怎麼解決 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.217.140.210