forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request geekcomputers#810 from swastik1308/master
Addition of email extraction program
- Loading branch information
Showing
3 changed files
with
1,931 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
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. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
counts=dict() | ||
mails=list() | ||
fname=input('Enter file name:') | ||
fh=open(fname) | ||
for line in fh: | ||
if not line.startswith('From'): | ||
continue | ||
if line.startswith('From:'): | ||
continue | ||
id=line.split() | ||
mail=id[1] | ||
mails.append(mail) | ||
for x in mails: | ||
counts[x]=counts.get(x,0)+1 | ||
bigmail=None | ||
bigvalue=None | ||
for key,value in counts.items(): | ||
if bigvalue==None or bigvalue<value: | ||
bigmail=key | ||
bigvalue=value | ||
print(bigmail, bigvalue) |
Oops, something went wrong.