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.
did without any functions but i guess using re would have been much simpler
deffun(s):# return True if s is a valid email, else return Falsel=[]valid_chars=['_',"-"]forstringins:temp=s.split("@")iflen(temp)==2:username,rest=tempelse:continueiflen(username)==0:continuetemp2=rest.split(".")iflen(temp2)==2:domain,extension=temp2else:continuec1=all([((x.isalnum())or(xinvalid_chars))forxinusername])c2=domain.isalnum()c3=extension.isalpha()c4=(len(extension)<4)and(len(extension)>0)ifc1andc2andc3andc4:l.append(string)returnldeffilter_mail(emails):returnlist(filter(fun,emails))if__name__=='__main__':n=int(input())emails=[]for_inrange(n):emails.append(input())
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 →
did without any functions but i guess using re would have been much simpler