Skip to content

Instantly share code, notes, and snippets.

@luiseduardobrito
Last active December 17, 2015 17:28
Show Gist options
  • Save luiseduardobrito/5645834 to your computer and use it in GitHub Desktop.
Save luiseduardobrito/5645834 to your computer and use it in GitHub Desktop.
Python script for cleaning a csv based on a ban list. (Used to clean big email lists)
import csv, sys, random
# num = qtd de emails a escolher
num = 40000
csv_file = "lista.csv"
out_file = "output.csv"
email_list = list(csv.reader(open(csv_file, 'r')))
result = []
for i in range(int(num)):
result.append(email_list.pop(random.choice(range(len(email_list)))))
with open(out_file, "wb") as f:
writer = csv.writer(f)
writer.writerows(result)
with open(csv_file, "wb") as f:
writer = csv.writer(f)
writer.writerows(email_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment