Python Practice › Set Programs › Program 21
Is a set a subset of any other set?
Write a Python program to check whether a set is a subset of any set in a list.
Input
{1, 2}; [{3, 4}, {1, 2, 5}, {6}]Output
True
Approach
any(target <= s for s in sets).
Solution
target = {1, 2}sets = [{3, 4}, {1, 2, 5}, {6}]print(any(target <= s for s in sets))Output
True
Learn the concept
New to this topic? Read the lesson, then come back.