Skip to content

Instantly share code, notes, and snippets.

@ayubmetah
Created January 6, 2021 21:45
Show Gist options
  • Save ayubmetah/77198352d611dcf981f67bd047f19796 to your computer and use it in GitHub Desktop.
Save ayubmetah/77198352d611dcf981f67bd047f19796 to your computer and use it in GitHub Desktop.
Write a program to read through the mbox-short.txt and figure out who has 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 appea…
add=dict()
name = input("Enter file:")
handle = open(name,'r')
for mail in handle:
if not mail.startswith('From '): continue
text=mail.split()
text=text[1]
add[text]=add.get(text,0)+1
print(text, add[text])
@ayubmetah
Copy link
Author

Write a program to read through the mbox-short.txt and figure out who has 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.

@ayubmetah
Copy link
Author

ayubmetah commented Jan 6, 2021

mbox-short

Attached is the mbox-short.txt file. Rename the file and it's extension to mbox-short.txt after downloading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment