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.
I didn't use emails.utils for my solution. Find my code below.
Just to precise, I started by splitting username / domain and extension into differents variables, then, I have created 3 differents regex pattern, to check if each one works.
When it was done, I've removed the split for username / domain and extension, then merge the 3 differents regex pattern into a big one.
And finally, it pass all the tests :
# Enter your code here. Read input from STDIN. Print output to STDOUTimportreimportemail.utilsn=int(input())output=list()for_inrange(n):current_line=input().split()if"@"incurrent_line[1]:current_name=current_line[0]current_mail=current_line[1]current_mail=current_mail[1:-1]pattern=r"^([A-Za-z][A-Za-z0-9\_\-\.]+)@([A-Za-z]+)([.])([A-Za-z]{1,3})$"# Debug check#print(bool(re.match(pattern, current_mail)))ifbool(re.match(pattern,current_mail)):output.append(current_line)else:continueelse:continueforelementinoutput:print(f"{element[0]} {element[1]}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Validating and Parsing Email Addresses
You are viewing a single comment's thread. Return to all comments →
I didn't use emails.utils for my solution. Find my code below.
Just to precise, I started by splitting username / domain and extension into differents variables, then, I have created 3 differents regex pattern, to check if each one works.
When it was done, I've removed the split for username / domain and extension, then merge the 3 differents regex pattern into a big one.
And finally, it pass all the tests :