Python Practice › Set Programs › Program 21

Is a set a subset of any other set?

EasySet Programs · 21 of 48

Write a Python program to check whether a set is a subset of any set in a list.

Advertisement
Input
{1, 2}; [{3, 4}, {1, 2, 5}, {6}]
Output
True

Approach

  1. any(target <= s for s in sets).

Solution

Python
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.

More set programs

← All 48 Set Programs

Leave a Comment