File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed
Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 1+ Hello Java!!!
2+ I love Java......
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments