Skip to content

Instantly share code, notes, and snippets.

@KKarthikeya
Created August 16, 2015 04:31
Show Gist options
  • Save KKarthikeya/e4896f398cdc3e6b6ce0 to your computer and use it in GitHub Desktop.
Save KKarthikeya/e4896f398cdc3e6b6ce0 to your computer and use it in GitHub Desktop.
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 a…
count = dict()
for line in open(raw_input("Enter File Name:")):
words = line.strip().split()
if len(words) == 0 or len(words) <3:
continue
if words[0] == 'From':
if words[1] not in count:
count[words[1]] = 1
else:
count[words[1]] += 1
max = 0
for key in count:
if count[key] > max:
max = count[key]
maxkey = key
print maxkey,count[maxkey]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment