Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The .txt file is a list of email addresses you collected for a conference your c

ID: 3580564 • Letter: T

Question

The .txt file is a list of email addresses you collected for a conference your company hosted. Create a program that will parse each email address by its name and company. The company should be sorted in the first column and the person’s name associated with the company should be sorted in the second column; separated with tab character. (first sort is by company; secondary sort is by firstname.lastname). Sample output is listed below:

amzn            bob.freed­­

amzn            caitlin.thomas

amzn            edward.flak

amzn            jill.bennet

Explanation / Answer

with open("emails.txt") as f:
    data = f.readlines()
l = []
for email in data:
    username = email[:email.find("@")]
    print email[email.find("@"):].find(".")
    companyname = email[email.find("@")+1:email.find("@")+email[email.find("@"):].find(".")]

    l.append((companyname, username))

l = sorted(l, key=lambda element: (element[0], element[1]))
for elem in l:
    print elem[0] + " " + elem[1]