You are viewing a single comment's thread. Return to all comments →
import re def fun(s): if '@' in s and '.' in s: c1=s.split('@') #username t1=bool(re.compile(r'^[a-zA-Z0-9_-]+$').match(c1[0])) c2=c1[1].split('.') #website t2=bool(re.compile(r'^[a-zA-Z0-9]+$').match(c2[0])) if len(c2)==2 else False if t2==True: #extension t3 = bool(re.compile(r'^[a-zA-Z]+$').match(c2[1])) if len(c2[1])<=3 else False else: t3=False return all([t1,t2,t3]) else: return False def filter_mail(emails): return list(filter(fun, emails)) if __name__ == '__main__': n = int(input()) emails = [] for _ in range(n): emails.append(input()) filtered_emails = filter_mail(emails) filtered_emails.sort() print(filtered_emails)
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 →