You are on page 1of 1

kmax = None

vmax = 0
name = input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
dic = dict()
for line in handle:
if line.startswith('From'):
n = line.split()
dic[n[1]] = dic.get(n[1],0) + 1

for key,val in dic.items():


if val>vmax:
vmax = val
kmax = key
print(kmax,int(vmax/2))

name = raw_input("Enter file:")


if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
text = handle.read()

senders = dict()
for line in handle:
if not line.startswith("From:"):continue
line = line.split()
line = line[1]
senders[line] = senders.get(line, 0) +1

bigcount = None
bigword = None
for word,sender in senders.items():
if bigcount == None or sender > bigcount:
bigword = word
bigcount = sender

print bigword, bigcount

You might also like