Articles

Program to find most widely used domain from a given set of 100 Emails in Python

Program to find most widely used domain from a given set of 100 Emails in Python


In this python programming article, we are going to learn

  • program to find most widely used domain from a given set of 100 emails in python

Program to find most widely used domain from a given set of 100 Emails in Python

The email list is as follows:

 

langosh.marques@gmail.com
windler.devyn@greenholt.org
okuneva.kirsten@streich.com
pkemmer@kling.com
claire69@yahoo.com
russell67@gmail.com
ona07@zulauf.info
stark.jalon@greenholt.org
abel30@herman.biz
rolfson.kyra@hotmail.com
cassidy63@hotmail.com
xschuster@gmail.com
lizzie.denesik@gmail.com
una.carroll@runolfsson.com
fidel55@dicki.org
rohan.blanca@hotmail.com
zparker@douglas.info
nstehr@tromp.com
zora15@yahoo.com
rahsaan17@hotmail.com
kuhn.ricky@hotmail.com
diego24@blick.com
francisco87@gmail.com
winifred.gislason@streich.com
denesik.naomi@hotmail.com
bosco.ariane@leffler.com
bergnaum.lindsay@gmail.com
jbradtke@skiles.com
krajcik.dovie@gmail.com
freddy33@nienow.com
mledner@gmail.com
doris67@yahoo.com
kiera04@yahoo.com
myrtis28@kris.com
wdenesik@yahoo.com
leola.swaniawski@hotmail.com
ufisher@yahoo.com
adrien88@lang.com
eupton@yahoo.com
yost.lexi@hotmail.com
ehermann@bogan.info
nschroeder@mertz.info
carleton.ratke@hotmail.com
ehalvorson@satterfield.com
bergstrom.shanelle@hotmail.com
rlangworth@rohan.info
mzemlak@considine.info
yost.lynn@gmail.com
ervin93@shields.info
charles17@wiza.org
janiya.little@doyle.com
leola.brown@hotmail.com
gstracke@gmail.com
schuppe.earline@gmail.com
huel.nona@gmail.com
sauer.simone@johnson.com
qhamill@gmail.com
matilde59@fahey.com
hagenes.damon@hotmail.com
velva.koelpin@doyle.com
ecassin@kunze.info
loren04@hotmail.com
terry.benton@yahoo.com
ekerluke@gmail.com
mabbott@dibbert.org
henderson.jakubowski@mohr.com
grant.jackson@yahoo.com
helmer.hartmann@jacobson.com
raegan.rutherford@hotmail.com
purdy.autumn@yahoo.com
deontae51@hotmail.com
taryn94@yahoo.com
marilyne.dach@yahoo.com
cyost@orn.com
velva.bayer@hudson.com
floyd.gislason@gmail.com
yazmin38@yahoo.com
pbuckridge@rippin.com
pwest@zemlak.biz
emiliano65@hotmail.com
mcdermott.rebecca@gusikowski.info
mann.esther@gmail.com
stark.kim@gmail.com
iortiz@franecki.com
gswift@ortiz.com
justine.wolf@kerluke.com
kkunze@carroll.com
hodkiewicz.candace@hotmail.com
goodwin.natasha@hotmail.com
rkeeling@hotmail.com
perry25@hotmail.com
mrodriguez@lang.biz
fschoen@hotmail.com
misty29@hotmail.com
brakus.jamarcus@jast.com
soledad.grimes@legros.com
ruthe96@pagac.com
wisoky.lourdes@hotmail.com
howell.amber@hotmail.com
preston.mohr@hotmail.com

The program is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

file = open("emails.txt","r")

domain_count = dict()

try:
    for i in file:
        i = i[i.index("@")+1:-1]
        domain_count[i] = domain_count.get(i, 0) + 1
except:
    pass

max_used_domain = None
max_count = 0
for domain, count in domain_count.items():
    if count > max_count:
        max_count = count
        max_used_domain = domain

print("Most used domain:", max_used_domain)

The output of the program is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Most used domain: hotmail.com

Few important tips about the program

1. We have used a dummy email list and saved it to a file name emails.txt.

2. We have opened the file using the open() function. "r" argument signifies file opening in reading mode in this case.

3. Slicing has been used to extract the domain from each given email and to ignore the next line character at the end of each line. 

4. From the dictionary, we iterate over both the keys and values to find the key with the highest value in this case.

 

program to find most widely used domain from a given set of 100 Emails.

 


Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Oct 13,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!