Skip to content

Commit aece417

Browse files
committed
0004
1 parent 6238d91 commit aece417

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

jhgdike/0004/solution.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# coding: utf-8
2+
3+
import re
4+
from collections import Counter
5+
6+
7+
def word_count(txt):
8+
word_pattern = r'[a-zA-Z-]+'
9+
words = re.findall(word_pattern, txt)
10+
return Counter(words).items()
11+
12+
if __name__ == '__main__':
13+
txt = open('test.txt', 'r').read().lower()
14+
print word_count(txt)

jhgdike/0004/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Henry was a pen name used by an American writer of short stories. His real name was William Sydney Porter. He was born in North Carolina in 1862. As a young boy he lived an exciting life. He did not go to school for very long, but he managed to teach himself everything he needed to know. When he was about 20 years old, O. Henry went to Texas, where he tried different jobs. He first worked on a newspaper, and then had a job in a bank, when some money went missing from the bank O. Henry was believed to have stolen it. Because of that, he was sent to prison. During the three years in prison, he learned to write short stories. After he got out of prison, he went to New York and continued writing. He wrote mostly about New York and the life of the poor there. People liked his stories, because simple as the tales were, they would finish with a sudden change at the end, to the reader¡¯s surprise.

out.jpg

2.15 KB
Loading

0 commit comments

Comments
 (0)