-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
45 lines (37 loc) · 921 Bytes
/
data.py
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
37
38
39
40
41
42
43
44
45
import string
def clear(word):
w = []
result = ''
pattern = string.punctuation
for i in word:
if i not in pattern:
w.append(i)
for i in w:
result += i
print(result)
return result
def analize():
pattern = string.punctuation + string.whitespace + '“' + "”"
file = open('Great leaders.txt', encoding="utf8")
word_list = []
dwords = {}
for s in file:
wl = s.lower().split()
for i in range(len(wl)):
wl[i] = wl[i].strip(pattern)
word_list += (wl)
for i in word_list:
dwords[i] = dwords.setdefault(i, 0) + 1
fwords = []
max = 0
mword = ''
for j in range(100):
for i in dwords:
if dwords[i] > max:
mword = i
max = dwords[i]
print(mword, max)
dwords[mword] = 0
max = 0
print(fwords)
analize()