Checking Subsets and Supersets

Write a Python program to check if a set is subset and superset of another set. The function should return a tuple containing two boolean values. First is True if the first set is a subset of the second set and False otherwise, and the second is True if the first set is a superset of the second set and False otherwise.

Example 1:

Input: {1, 2, 3}, {1, 2, 3, 4, 5} 
Output: (True, False)

Example 2:

Input: {1, 2, 3, 4, 5}, {1, 2, 3} 
Output: (False, True)

Use the issubset() and issuperset() methods in Python.

def check_subset_superset(set1, set2):
    return set1.issubset(set2), set1.issuperset(set2)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!