Skip to content

Instantly share code, notes, and snippets.

@natemurthy
Last active August 29, 2015 14:01
Show Gist options
  • Save natemurthy/e75ddd46af2a7368f3e3 to your computer and use it in GitHub Desktop.
Save natemurthy/e75ddd46af2a7368f3e3 to your computer and use it in GitHub Desktop.
inputFile = open('names_emails.txt')
names_emails = inputFile.read(); inputFile.close()
nameEmailArray = names_emails.split(",")
nameEmailDict = {}; emailOnly = []
for name_email in nameEmailArray:
token = name_email.split(' <')
if len(token) == 1:
emailOnly.append(token[0].replace('>',''))
elif len(token) == 2:
nameEmailDict[token[0]] = token[1].replace('>','')
for item in emailOnly:
print item
import csv
outputFile = open('namesAndEmails.csv', 'wb')
writer = csv.writer(outputFile)
for k, v in nameEmailDict.items():
writer.writerow([k, v])
outputFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment