Skip to content

Commit 532fa65

Browse files
authored
Merge pull request Show-Me-the-Code#225 from Levantado/master
Simple solution
2 parents ab34ff5 + c9e0e21 commit 532fa65

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

levantado/0004/word.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
l am the big big boy in the world;
3+
The world is big big include the boy ;

levantado/0004/worder.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
import os
3+
from pprint import pprint
4+
5+
path = os.getcwd() + '/word.txt'
6+
7+
8+
def wordstat(path):
9+
f = open(path, 'r+')
10+
wordcount = {}
11+
for t in re.sub('[^0-9a-zA-Z]+', " ", f.read()).split():
12+
if t not in wordcount:
13+
wordcount[t] = 1
14+
else:
15+
wordcount[t] += 1
16+
pprint(wordcount)
17+
18+
19+
if __name__ == '__main__':
20+
wordstat(path)

0 commit comments

Comments
 (0)