Intersection of Sets

Write a Python program to return the intersection of two sets.

Example 1:

Input: {1, 2, 3, 4, 5}, {4, 5, 6, 7, 8} 
Output: {4, 5}

Example 2:

Input: {5, 7, 8, 9, 10}, {1, 2, 3} 
Output: set()

Use the intersection() function to get the common elements of two sets.

def intersection_of_sets(s1, s2):
    return s1.intersection(s2)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!