Validating and Parsing Email Addresses

  • + 0 comments

    import email.utils name="" user="" domain="" ext="" a=[] out="" new_str=""

    n=int(input())

    def validity(n,u,d,e):

    if u[0].isalpha() and "@" not in u:
    
        out=n+"<"+u+"@"
        if d.isalpha():
            out+=d
            if len(e)<=4 and len(e)>0:
                if e.isalpha():
    
                    out+="."+e+">"        
                    print(out)
    

    for i in range(n): a.append(input())

    for email in a: if "<" in email: name,mail=email.split("<",1) if "@" in mail: user, domain_with_ext = mail.split("@", 1)

            if "." in domain_with_ext:
                domain, exten = domain_with_ext.split(".", 1)
    
                if ">" in exten:
                    ext,new_str=exten.split(">",1)
                    validity(name,user,domain,ext)