Intersection and other operations on CSV file
I have sent an email campaign to the wrong list, so to get a sense of what's going on (who opened it, who clicked) I made this little script
import csv
a = set()
with open('a.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for r in spamreader:
a.add((r[0],r[1],r[2])) # I only needed email, first and last name
b = set()
with open('b.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for r in spamreader:
b.add((r[0],r[1],r[2]))
intersection = a & b
for x in intersection:
print ",".join(x)
Since they are represented as sets you can do subtraction, union etc.
Written by lukas
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#