Given:
first_set = {23, 42, 65, 57, 78, 83, 29} second_set = {57, 83, 29, 67, 73, 43, 48}
Expected Output:
Intersection is {57, 83, 29} First Set after removing common element {65, 42, 78, 23}
Hint:
intersection()
remove()
Solution:
first_set.intersection(second_set)
first_set = {23, 42, 65, 57, 78, 83, 29} second_set = {57, 83, 29, 67, 73, 43, 48} print("First Set ", first_set) print("Second Set ", second_set) intersection = first_set.intersection(second_set) print("Intersection is ", intersection) for item in intersection: first_set.remove(item) print("First Set after removing common element ", first_set)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
intersection()andremove()method of a setSolution:
- Get the common items using the
- Next, iterate common items using a for loop
- In each iteration, use the
need an explanation for this answer? contact us directly to get an explanation for this answerfirst_set.intersection(second_set)remove()method of on first set and pass the current item to it.