Question

Chinthala Abril Schuhmann Ajwa Degruccio Burkhart Huddleston Cooper Rambarran Draper Bruederle Epps Buchanan Goulet Reiter Griffith...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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)

Add a comment
Know the answer?
Add Answer to:
Chinthala Abril Schuhmann Ajwa Degruccio Burkhart Huddleston Cooper Rambarran Draper Bruederle Epps Buchanan Goulet Reiter Griffith...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT