Input Format
The first line of input is the integer , the number of email addresses.
 lines follow, each containing a string.
Each line is a non-empty string.
Output Format
Output a list containing the valid email addresses in lexicographical order. If the list is empty, just output an empty list, [].

hackerrank validating email address with a filter problem solution in python

Problem solution in Python 3 programming language.

import re
lst = list()
for i in range(int(input())):
print(sorted(list(filter(lambda x:'^[\w\d-]+@[A-Za-z0-9]+\.\w?\w?\w$',x),lst))))

Second solution

def fun(email):
        username, url = email.split("@")
        website, extension = url.split(".")
    except ValueError:
        return False
    if username.replace("-""").replace("_""").isalnum() is False:
        return False
    elif website.isalnum() is False:
        return False
    elif len(extension) > 3:
        return False
        return True
def filter_mail(emails):
    return list(filter(fun, emails))
if __name__ == '__main__':
    n = int(input())
    emails = []
    for _ in range(n):
filtered_emails = filter_mail(emails)

Problem solution in Python 2 programming language.

import re
lst = list()
for i in range(int(raw_input())):
print sorted(list(filter(lambda x:'^[\w\d-]+@[A-Za-z0-9]+\.\w?\w?\w$',x),lst)))