8000 update word _statistic.py · mikephp/basic_data_struct@00458cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 00458cd

Browse files
committed
update word _statistic.py
1 parent f003a97 commit 00458cd

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/python/word_statistic.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
#!/bin/python
12
#encoding=utf-8
23
import os,time,sys
34
word_lst = []
45
word_dict = {}
5-
path = sys.path[0]
6+
67
#encoding=utf-8
7-
with open(path+"\\zw.txt","r") as f1 ,open(path+"\\ccs.txt",'w') as f2:
8-
for line in f1:
9-
word_lst.append(line.split('/'))
10-
for item in word_lst:
11-
for item2 in item:
12-
if item2.strip() not in ",!。“”" :
13-
if item2 not in word_dict:
14-
word_dict[item2] = 1
15-
else :
16-
word_dict[item2] += 1
17-
for key in word_dict:
18-
print key,word_dict[key]
19-
f2.write(key+' '+str(word_dict[key])+'\n')
8+
def word_statistics(input_file,output_file):
9+
path = sys.path[0]
10+
debug = 1
11+
if debug:
12+
print path
13+
with open(path+"\\"+input_file,"r") as f1 ,open(path+"\\"+output_file,'w') as f2:
14+
for line in f1:
15+
tmp = line.split('/')
16+
#print type(tmp)
17+
#print tmp
18+
word_lst.append(tmp)
19+
#print word_lst
20+
for item in word_lst:
21+
#print item
22+
for item2 in item:
23+
if item2.strip() not in ",!。“”" :
24+
if item2 not in word_dict:
25+
word_dict[item2] = 1
26+
else :
27+
word_dict[item2] += 1
28+
29+
for key in word_dict:
30+
#print key,word_dict[key]
31+
f2.write(key+' '+str(word_dict[key])+'\n')
32+
33+
word_statistics("zw.txt","css.txt")

0 commit comments

Comments
 (0)
0