We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
deffun(s):ifs.count('@')!=1:returnFalseusername=s.split('@')[0]domain=s.split('@')[1]# Ensure domain has at least one dotif'.'notindomain:returnFalseifnotusername:returnFalsewebsite=domain.split('.')[0]extension=domain.split('.')[-1]res=[1,1,1]# Check usernameforiinusername:ifres[0]==0:breakifi.isalnum()oriin['-','_']:res[0]=1else:res[0]=0# Check website only if username is validifres==[1,1,1]:forjinwebsite:ifres[1]==0:breakifj.isalnum():res[1]=1else:res[1]=0# Check extension only if username and website are validifres==[1,1,1]:iflen(extension)<=3andlen(extension)>0:forkinextension:ifres[2]==0:breakifk.isalpha():res[2]=1else:res[2]=0else:res[2]=0# Return True if all checks passedreturnres==[1,1,1]deffilter_mail(emails):returnlist(filter(fun,emails))if__name__=='__main__':n=int(input())emails=[]for_inrange(n):emails.append(input())filtered_emails=filter_mail(emails)filtered_emails.sort()print(filtered_emails)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Validating Email Addresses With a Filter
You are viewing a single comment's thread. Return to all comments →
Try this