Skip to content

Commit b46e227

Browse files
author
Shaoyuan Li
committed
python test 0004
1 parent 20205a2 commit b46e227

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

ShaoyuanLi/0004/0004.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: cp936 -*-
2+
import re
3+
fin=open("example.txt","r")
4+
fout=open("result.txt","w")
5+
str=fin.read()
6+
#匹配正则表达式
7+
reObj=re.compile("\b?([a-zA-Z]+)\b?")
8+
words=reObj.findall(str)
9+
#建立空字典
10+
word_dict={}
11+
#以单词的小写作为键值进行统计,同时要
12+
for word in words:
13+
if(word_dict.has_key(word)):
14+
word_dict[word.lower()]=max(word_dict[word.lower()],words.count(word.lower())+words.count(word.upper())+words.count(word))
15+
else:
16+
word_dict[word.lower()]=max(0,words.count(word.lower())+words.count(word.upper())+words.count(word))
17+
for(word,number) in word_dict.items():
18+
fout.write(word+":%d\n"%number)
19+

ShaoyuanLi/0004/example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In the latest move to support the economy, Shanghai, Beijing, Chongqing and six other provinces and municipalities will allow banks to refinance high-quality credit assets rated by the People's Bank of China, said the central bank, as the program was first introduced in Guangdong and Shandong provinces last year.

ShaoyuanLi/0004/result.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
and:6
2+
beijing:1
3+
shandong:1
4+
six:2
5+
people:1
6+
move:2
7+
year:2
8+
high:2
9+
as:2
10+
program:2
11+
in:2
12+
guangdong:1
13+
quality:2
14+
provinces:4
15+
rated:2
16+
support:2
17+
shanghai:1
18+
to:4
19+
other:2
20+
was:2
21+
economy:2
22+
municipalities:2
23+
refinance:2
24+
said:2
25+
china:1
26+
last:2
27+
by:2
28+
bank:2
29+
chongqing:1
30+
introduced:2
31+
central:2
32+
assets:2
33+
of:2
34+
will:2
35+
credit:2
36+
s:2
37+
allow:2
38+
banks:2
39+
the:10
40+
first:2
41+
latest:2

0 commit comments

Comments
 (0)