Write a program to read through the mbox-short.txt and figure out who has the sent the greatest number of mail messages.
The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail.
The program creates a Python dictionary that maps the sender's mail address to a count of the number of times they appear in the file.
After the dictionary is produced, the program reads through the dictionary using a maximum loop to find the most prolific committer
name = raw_input("Enter file:")
if len(name) < 1 :
name = "mbox-short.txt"
cou = dict()
res = 0
handle = open(name)
for line in handle:
line = line.rstrip()
if line == '':
continue
words = line.split()
if words[0] == 'From':
cou[words[1]] = cou.get(words[1], 0) + 1
if cou[words[1]] > res:
res = cou[words[1]]
word = words[1]
print word, res
The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail.
The program creates a Python dictionary that maps the sender's mail address to a count of the number of times they appear in the file.
After the dictionary is produced, the program reads through the dictionary using a maximum loop to find the most prolific committer
name = raw_input("Enter file:")
if len(name) < 1 :
name = "mbox-short.txt"
cou = dict()
res = 0
handle = open(name)
for line in handle:
line = line.rstrip()
if line == '':
continue
words = line.split()
if words[0] == 'From':
cou[words[1]] = cou.get(words[1], 0) + 1
if cou[words[1]] > res:
res = cou[words[1]]
word = words[1]
print word, res