Skip to content

Instantly share code, notes, and snippets.

@nitesh8860
Created June 12, 2020 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitesh8860/f3aaffb2a723eb0e976d6acabcd01897 to your computer and use it in GitHub Desktop.
Save nitesh8860/f3aaffb2a723eb0e976d6acabcd01897 to your computer and use it in GitHub Desktop.
def fun(s):
# return True if s is a valid email, else return False
import re
rex = re.compile("^[\w\-\_]+\@[a-zA-Z0-9]+\.\w{1,3}$")
if rex.match(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)
#Sample Input
#2
#harsh@gmail
#iota_98@hackerrank.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment