Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions jhgdike/0004/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding: utf-8

import re
from collections import Counter


def word_count(txt):
word_pattern = r'[a-zA-Z-]+'
words = re.findall(word_pattern, txt)
return Counter(words).items()

if __name__ == '__main__':
txt = open('test.txt', 'r').read().lower()
print word_count(txt)
1 change: 1 addition & 0 deletions jhgdike/0004/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +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.