We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e045b74 commit fc9b8a6Copy full SHA for fc9b8a6
Jaccorot/0004/0004.py
@@ -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
@@ -0,0 +1,3 @@
+cocococo asdf asdf asdf sdf
+sdf
0 commit comments