Checking for a Subset

Tags: Set, subset

Write a Python program to check if a set is a subset of another set. The function should return True if the first set is a subset of the second, False otherwise.

Example 1:

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

Example 2:

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

Use the issubset() method in Python.

def check_subset(set1, set2):
    return set1.issubset(set2)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!