belongs to collection: Python Set Exercises
Given:
set1 = {10, 20, 30, 40, 50} set2 = {60, 70, 80, 90, 10}
Expected output:
Two sets have items in common {10}
Hint:
isdisjoint()
intersection()
Solution:
set1 = {10, 20, 30, 40, 50} set2 = {60, 70, 80, 90, 10} if set1.isdisjoint(set2): print("Two sets have no items in common") else: print("Two sets have items in common") print(set1.intersection(set2))
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:
isdisjoint()
method check if sets has a common elementsintersection()
method to display common elementsSolution:
need an explanation for this answer? contact us directly to get an explanation for this answer