Created
February 11, 2022 17:23
-
-
Save VinayReddy-Vangala/abe466931333ad69f94e2f80e53c359f to your computer and use it in GitHub Desktop.
9.4 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 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
name = input("Enter file:") | |
if len(name) < 1: | |
name = "mbox-short.txt" | |
handle = open(name) | |
kv_book=dict() | |
list1=[] | |
for line in handle: | |
if line.startswith('From '): | |
split=line.split() | |
list1.append(split[1]) | |
for names in list1: | |
kv_book[names]=kv_book.get(names,0)+1 | |
biggest_count=None | |
biggest_word=None | |
for k,v in kv_book.items(): | |
if biggest_count is None or v>biggest_count: | |
biggest_word=k | |
biggest_count=v | |
print(f"{biggest_word} {biggest_count}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment