Last active
July 26, 2017 21:38
-
-
Save JulianNorton/bdd0c825eb5f327299abcd6444200cca to your computer and use it in GitHub Desktop.
compare lists, match and dupe, detector.
This file contains hidden or 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
import csv | |
csvfile_A = 'example.csv' | |
csvfile_B = 'anotherexample.csv' | |
delimiter = '\n' | |
data_alpha = [] | |
data_beta = [] | |
data_matched = list() | |
data_no_matched = list() | |
with open(csvfile_A, newline='') as csvfile_A: | |
csvfile_A = csv.reader(csvfile_A, delimiter=delimiter, quotechar='|') | |
for item in csvfile_A: | |
data_alpha.append(item) | |
with open(csvfile_B, newline='') as csvfile_B: | |
csvfile_B = csv.reader(csvfile_B, delimiter=delimiter, quotechar='|') | |
for line in csvfile_B: | |
data_beta.append(line) | |
# Does the item in Alpha appear in Beta? | |
for item in data_alpha: | |
found_items = 0 | |
if item in data_beta: | |
print(item, 'found') | |
data_matched.append(item[0]) | |
else: | |
print(item[0], 'not found') | |
data_no_matched.append(item[0]) | |
print(len(data_matched),'matched data',data_matched) | |
print('\n','+++++++','\n') | |
print(len(data_no_matched),'unmatched data',data_no_matched) | |
with open('output.csv', 'w', newline='') as myfile: | |
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL) | |
wr.writerow([data_matched]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment