Created
August 16, 2015 04:31
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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