Skip to content

Commit e1726b4

Browse files
committed
finish 0006
1 parent aad5b02 commit e1726b4

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

Silocean/0006/Test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*-coding:utf-8-*-
2+
__author__ = 'Tracy'
3+
import os,re
4+
5+
path = 'diaries'
6+
files = os.listdir(path)
7+
8+
def get_key_word(words):
9+
dic = {}
10+
max = 0
11+
marked_key = ''
12+
for word in words:
13+
if dic.has_key(word) is False:
14+
dic[word] = 1
15+
else:
16+
dic[word] = dic[word] + 1
17+
for key, value in dic.items():
18+
if dic[key] > max:
19+
max = dic[key]
20+
marked_key = key
21+
print(marked_key, max)
22+
23+
24+
for f in files:
25+
with open(os.path.join(path, f)) as diary:
26+
words = re.findall("[a-zA-Z]+'*-*[a-zA-Z]*",diary.read())
27+
get_key_word(words)

Silocean/0006/diaries/day01.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Python learning
2+
3+
This is a diary about Python.
4+
Python is an interesting language, which is very easy to learn and we can use it to do many things.

Silocean/0006/diaries/day02.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hello Java!!!
2+
I love Java......

Silocean/0006/diaries/day03.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The Dursleys had everything they wanted, but they also had a secret,
2+
and their greatest fear was that somebody would discover it.
3+
They didn't think they could bear it if anyone found out about the Potters.
4+
Mrs. Potter was Mrs. Dursley's sister, but they hadn't met for several years;
5+
in fact, Mrs. Dursley pretended she didn't have a sister, because her sister and her good-for-nothing
6+
husband were as unDursleyish as it was possible to be.
7+
The Dursleys shuddered to think what the neighbors would say if the Potters arrived in the street.
8+
The Dursleys knew that the Potters had a small son, too, but they had never even seen him.
9+
This boy was another good reason for keeping the Potters away; they didn't want Dudley mixing with a child like that

0 commit comments

Comments
 (0)