We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cbf0227 commit 456ba7dCopy full SHA for 456ba7d
2 files changed
chris5641/0004/GetWordNum.py
@@ -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
@@ -0,0 +1,3 @@
+Microsoft's is a big, computer compony.
+this is a test!
0 commit comments