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.
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())
Validating Email Addresses With a Filter
You are viewing a single comment's thread. Return to all 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)