An Interest In:
Web News this Week
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
- April 12, 2024
Day 34 Of 100DaysOfCode : Python Code To Find Count Of Mail
Today is my 34 day of #100DaysOfCode and Python. Today I tried to write some code on python access to web data and data structure on python. Complete some assignment on coursera.
Below is the python code I tried to write to find the count of mail from the file and from whom maximum times mail come.
Python Code
At first we open file. Set counts to zero at first. There is empty list for mails. I write simple loop to find the mail. There is empty dictionary to store mail as a key and number of count as a value.
fhand = open('mbox-short.txt')count = 0emails = []for line in fhand: words = line.split() # print('Debug:', words) if len(words) == 0 : continue if words[0] != 'From' : continue emails.append(words[1])#print(emails)d = {}for email in emails: if email not in d: d[email] = 1 else: d[email] += 1#print(d)max(d)nd = {k: v for k, v in list(reversed(sorted(d.items(), key=lambda item: item[1])))}nd
The output of this code is given below.
{'[email protected]': 5, '[email protected]': 4, '[email protected]': 4, '[email protected]': 3, '[email protected]': 3, '[email protected]': 2, '[email protected]': 2, '[email protected]': 1, '[email protected]': 1, '[email protected]': 1, '[email protected]': 1}
To find by whom we got maximum mail is find by
print(f"This {list(nd.items())[0][0]} send mail most i.e {list(nd.items())[0][1]} times.")
Output is,
This cwen@iupui.edu send mail most i.e 5 times.
Day 34 Of #100DaysOfCode and #Python
Durga Pokharel (@mathdurga) January 27, 2021
* Web access on python
* Data structure on python
* Python program to find the maximum count of mail.#100DaysOfCode ,#CodeNewbie ,#Python ,#beginners pic.twitter.com/pTaNyNoczI
Original Link: https://dev.to/iamdurga/day-34-of-100daysofcode-python-code-to-find-count-of-mail-4ddh
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To