I am trying to read in a csv file: base_list.csv
- CSV file with two columns
Then read in file_1.csv
and remove and matching values from the base_list.csv
file, and
write those out to a new csv file called Dups.csv
When I run this I am getting the following error:
emails = set(emails) #"set" removes duplicates in a list TypeError: unhashable type: 'list'
Sample code below:
import csv
#gather emails from base_list:
with open("H:\\Python Backups\\DeDup\\ByCSV\\base_list.csv", "rU") as base_file:
read_base_file = csv.reader(base_file, delimiter=",")
duplicates_list = []
rows = [row for row in read_base_file]
for row in rows:
duplicates_list.extend(row)
#extract emails from other csv files (csv_files) from multiple
#columns in those csv files (email_columns):
emails = []
with open("H:\\Python Backups\\DeDup\\ByCSV\\file_1.csv", "rU") as csvfile:
read_csv = csv.reader(csvfile, delimiter=",")
email_rows = [r for r in read_csv]
emails.extend(email_rows)
#find duplicates from base_list and remove them:
duplicates = [e for e in emails if e in duplicates_list]
for dupe in duplicates:
emails.remove(dupe)
emails = set(emails) #"set" removes duplicates in a list
#write the emails to a csv:
writer = csv.writer(open("H:\\Python Backups\\DeDup\\ByCSV\\Dups.csv", "ab"))
for email in zip(emails):
writer.writerow(email)