forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0006.py
More file actions
36 lines (35 loc) · 773 Bytes
/
0006.py
File metadata and controls
36 lines (35 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#coding=utf-8
#拿以前代码改的
import re,sys,os
path = os.path.split(os.path.realpath(__file__))[0]+"/"
Fliter = re.compile("[^A-Za-z-\']|((?<![A-Za-z])[-\'])|([-\'](?![A-Za-z]))")
Divider = re.compile("\s")
File = open(path+"list.txt").read()
ex = re.split("[\r\n]",File)
ex.append(" ")
ex.append("")
ex = list(set(ex))
def Stat(input):
Dict = {}
File = open(input).read()
Data = Divider.split(Fliter.sub(" ",File))
for i in Data:
j = i.lower()
try:
Dict[j]+=1
except KeyError:
Dict[j] =1
except:
raise
for i in ex:
j = i.lower()
try:
del(Dict[j])
except KeyError:
pass
except:
raise
return sorted(Dict.items(),key = lambda i:i[1],reverse=True)[0][0]
ls = os.listdir(path+"src/")
for i in ls:
print i,Stat(path+"src/"+i)