Answer to Question #209461 in Python for R SWASTHIK

Question #209461

Set1 and Set2 are the two sets that contain unique integers. Set3 is to be created by taking the union or intersection of Set1 and Set2 using the user defined function Operation(). Perform either union or intersection by reading choice from user. Do not use built in functions union() and intersection() and also the operators “|” and “&“.


1
Expert's answer
2021-06-23T02:56:37-0400
set1 = [1,2,3,4,5,6] #Example of a set1
set2 = [1,2,3,5,7,9,10] #Example of a set2
set3 = []
def Operation(choice):
    if choice == "union":
        for row in set2:
            set1.append(row)
            
        for col in set1:
            set3.append(col)
    elif choice == "intersection":
        for row in set1:
            if row in set2:
                set3.append(row)
        for col in set2:
            if col in set1:
                set3.append(col)
    return set(set3)
print(Operation("union"))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS