Apr-21-2021, 10:59 PM
Hi Everyone,
I have been stuck with this question for a whole week. The staff of our course is not helpful at all. Hope I could get any clue from you guys. Thanks.
This is my assignment:
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.
File mbox-short:https://www.py4e.com/code3/mbox-short.txt
This is my code to it:
I tried to loop over the x as"For word in x:", then it comes out to count everything such as from, emails, time and dates. In this case how can I pick up only the emails and its counts? Thank you!
I have been stuck with this question for a whole week. The staff of our course is not helpful at all. Hope I could get any clue from you guys. Thanks.
This is my assignment:
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.
File mbox-short:https://www.py4e.com/code3/mbox-short.txt
This is my code to it:
name=input("Enter file: ") fh=open(name) largest=None counts=dict() for line in fh: if line.startswith("From "): x=line.split() emails=x[1] print(emails) for word in emails: counts[word]=counts.get(word,0)+1 if largest is None or counts[word] > largest: largest=counts[word] print(counts,largest)It comes out to count every alphabet but not a single email. How can I count the emails?
I tried to loop over the x as"For word in x:", then it comes out to count everything such as from, emails, time and dates. In this case how can I pick up only the emails and its counts? Thank you!