Skip to content

Commit fc9b8a6

Browse files
committed
add 0004
1 parent e045b74 commit fc9b8a6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Jaccorot/0004/0004.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/local/bin/python
2+
#coding=utf-8
3+
4+
"""
5+
第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。
6+
"""
7+
import re
8+
9+
def count_the_words(path):
10+
with open(path) as f:
11+
text = f.read()
12+
words_list = re.findall(r'[a-zA-Z0-9]+', text)
13+
count = len(words_list)
14+
return count
15+
16+
if __name__ == '__main__':
17+
nums = count_the_words('file.txt')
18+
print nums

Jaccorot/0004/file.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cocococo asdf asdf asdf sdf
2+
sdf
3+
sdf

0 commit comments

Comments
 (0)