Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 统计文本中的单词数目 #11

Open
lionzhnn opened this issue Apr 16, 2018 · 0 comments
Open

python 统计文本中的单词数目 #11

lionzhnn opened this issue Apr 16, 2018 · 0 comments

Comments

@lionzhnn
Copy link

`#!/usr/bin/env python
#encoding=utf-8
import re
import string
print 'kill game by input end'
f=open("python_string_test.txt"); #count file
result=0;
identify=string.maketrans('','')
delEstr = string.punctuation + string.digits; #remove pounction and digit
for line in f.readlines(): #count each line
cleanline=line.translate(identify,delEstr);
lineArr = re.split(' ',cleanline);
index=0;
temp=[];
#remove '\n',''
while index<len(lineArr):
if lineArr[index]=='\n':
temp.append(str(index))
if lineArr[index]=='':
temp.append(str(index))
index=index+1;
index=0;
while index<len(temp):
lineArr.pop(len(temp)-index-1);
index=index+1;
result=result+len(lineArr);
print str(result); #result

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant