Created
December 2, 2019 12:35
-
-
Save corolla96/6a2d8e5db28639e7bea020a46aa88ed2 to your computer and use it in GitHub Desktop.
find common emails from two lists (intersection from two sets)
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
import csv | |
def intersection(list1, list2): | |
""" | |
Find the unique intersection of two lists and return the intersection as a list. | |
""" | |
return [value for value in list1 if value in list2] | |
if __name__ == "__main__": | |
lists = [] | |
with open('file-name.csv') as csv_file: | |
rows = csv.reader(csv_file, delimiter=',') | |
for row in rows: # row looks like a@a.com b@b.com | |
lists.append(list(row)) # put row in a list and append to lists | |
res_list = intersection(lists[0], lists[1]) | |
print(res_list) # print the intersected result list of two lists | |
print(len(res_list)) # printing the length of the list tells us | |
# how many emails are common in two lists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment