-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistogram.py
More file actions
47 lines (40 loc) · 972 Bytes
/
histogram.py
File metadata and controls
47 lines (40 loc) · 972 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
37
38
39
40
41
42
43
44
45
46
47
try:
fileHandel = open('mbox.txt')
except:
print("File not found")
exit()
histo = dict()
words = []
for line in fileHandel:
if len(line.strip())!=0:
line.rstrip()
words = line.split()
# print('Debug:',words)
if words[0]=='From':
word = words[1]
if histo.get(word,0) == 0:
histo[word] = 1
else:
histo[word] +=1
else:
continue
# for x in histo:
# print(x,histo[x])
all_stuff = list(histo.keys())
# print(all_stuff)
# print(all_stuff[1])
low = all_stuff[0]
high = all_stuff[0]
# print(high,low)
# highest = histo[0]
# lowest = histo[0]
for x in histo:
# print("Debug:",x)
if histo[x] > histo[high]:
high = x
# print("Debug:",x,histo[high],histo[low])
if histo[x] < histo[low]:
low = x
else:
continue
print(high,histo[high],low,histo[low])