Skip to content

Instantly share code, notes, and snippets.

@corolla96
Created December 2, 2019 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corolla96/6a2d8e5db28639e7bea020a46aa88ed2 to your computer and use it in GitHub Desktop.
Save corolla96/6a2d8e5db28639e7bea020a46aa88ed2 to your computer and use it in GitHub Desktop.
find common emails from two lists (intersection from two sets)
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