作者yungyuc (酷狗喵千代)
看板Python
标题Re: [问题] 请问一下读档的问题
时间Fri Mar 16 11:27:12 2007
※ 引述《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