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.
Validating Email Addresses With a Filter
Validating Email Addresses With a Filter
+ 0 comments import re def fun(s): pattern = re.compile(r'^[a-zA-Z0-9_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$') return pattern.match(s)
+ 0 comments def fun(s): return re.match( r'^[a-zA-Z0-9_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$', s)
+ 0 comments import re def fun(s): # return True if s is a valid email, else return False if bool(re.fullmatch('^[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[.][a-zA-Z]{,3}$', s)): return(True) 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)
+ 0 comments whats the runtime error in these code
def fun(s): # return True if s is a valid email, else return False if "@" in s: username, rest = s.split('@') if "." in rest: web_name, ext = rest.split('.') if username and web_name and ext.isalpha() and len(ext) <= 3 and web_name.isalnum() and all(ch.isalnum() or ch in '-_' for ch in username): return True return False def filter_mail(emails): return list(filter(fun, emails))
if name == 'main': n = int(input()) emails = [] for email in range(n): emails.append(input())
filtered_emails = filter_mail(emails) filtered_emails.sort() print(filtered_emails)
+ 0 comments def fun(s): return bool(re.match(r"^[a-zA-Z0-9\-_]+@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$", s))
Load more conversations
Sort 539 Discussions, By:
Please Login in order to post a comment