Skip to content

Commit 456ba7d

Browse files
committed
0004
1 parent cbf0227 commit 456ba7d

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

chris5641/0004/GetWordNum.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。
4+
"""
5+
import re
6+
__author__ = 'Chris5641'
7+
8+
9+
def get_num():
10+
num = 0
11+
f = open('test.txt', 'r')
12+
for line in f.readlines():
13+
num += len(re.findall(r'[a-zA-Z0-9\']+', line))
14+
f.close()
15+
return num
16+
17+
18+
if __name__ == '__main__':
19+
print(get_num())

chris5641/0004/test.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Microsoft's is a big, computer compony.
2+
this is a test!
3+

0 commit comments

Comments
 (0)