Last active
August 29, 2015 14:01
-
-
Save natemurthy/e75ddd46af2a7368f3e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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