作者isong (船没开啊...)
看板Python
标题[问题] 请问一下读档的问题
时间Sat Mar 3 23:47:26 2007
最近在练习读档的问题
假如我有一个档 "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