| Chinthala | Abril |
| Schuhmann | Ajwa |
| Degruccio | Burkhart |
| Huddleston | Cooper |
| Rambarran | Draper |
| Bruederle | Epps |
| Buchanan | Goulet |
| Reiter | Griffith |
| Stinnett | Grigsby |
| Jackson | Hadley |
| Czajka | Jenkins |
| Midle | Jha |
| Sunuwar | Phillabaum |
| Bright | Roberson |
| Kim | Ruth |
| Urbaniak | Urbaniak |
| Sanders | Wilson |
| Garcia | |
| Williams | |
| Schimpf | |
| Paul | |
| Turner | |
| Draper | |
| Doan | |
| Griffith | |
| Vanaparthy | |
| Schmidt | |
| Spalding | |
| Skellie | |
| Seth | |
| Webb | |
| Wichmann | |
| Chestnut |
Use python to determine which names are in column 1 but not column 0, which are in column 0 but not column 1, and which are in both.
In my current code I am using a csv file. However, I am not getting appropriate results.
import csv
with open('filename.csv','r') as csv_file:
csv_reader = csv.reader(csv_file)
for line in csv_reader:
print(line)
A = line[0]
B = line[1]
sA = set(A)
sB = set(B)
Intersection = sA.intersection(sB)
OnlyA = sA.difference(sB)
OnlyB = sB.difference(sA)
Intersection, OnlyA, OnlyB
If you have any doubts, please give me comment...


Code:
import csv
with open('filename.csv','r') as csv_file:
csv_reader = csv.reader(csv_file)
sA = []
sB = []
for line in csv_reader:
# print(line)
A = line[0]
sA.append(A)
if(len(line)>1):
B = line[1]
sB.append(B)
sA = set(sA)
sB = set(sB)
Intersection = sA.intersection(sB)
OnlyA = sA.difference(sB)
OnlyB = sB.difference(sA)
print("Intersection:")
print(Intersection)
print("\nOnlyA:")
print(OnlyA)
print("\nOnly B:")
print(OnlyB)
Chinthala Abril Schuhmann Ajwa Degruccio Burkhart Huddleston Cooper Rambarran Draper Bruederle Epps Buchanan Goulet Reiter Griffith...