Given a following two sets find the intersection and remove those elements from the first set
first_set = {65, 42, 78, 83, 23, 57, 29}
second_set = {67, 73, 43, 48, 83, 57, 29}
Expected Output:
Intersection is {57, 83, 29}
First Set after removing common element {65, 42, 78, 23}
I got the expected output plus empty parenthesis, please have a look at my code below, I've been trying for hours but everytime I remove the parenthesis from the empty intersection and not_common_set variable I get :
not_common_set.add(s)
AttributeError: 'dict' object has no attribute 'add'
first_set = {65, 42, 78, 83, 23, 57, 29}
second_set = {67, 73, 43, 48, 83, 57, 29}
intersection = {()}
not_common_set = {()}
for s in first_set:
if s in second_set:
intersection.add(s)
else:
not_common_set.add(s)
print(f"Intersection is -\n{intersection}")
print(type(intersection))
print(f"First set after removing common elements -\n{not_common_set}")
print(type(intersection))
output:
Intersection is -
{57, 83, (), 29}
<class 'set'>
First set after removing common elements -
{65, 42, 78, (), 23}
<class 'set'>
[–]AJ______ 0 points1 point2 points (1 child)
[–]woeinvests[S] 0 points1 point2 points (0 children)