Program to check is a set is a subset of another set in Python
In this python programming article, we are going to learn
-
program to check if a set is a subset of another set in python
Program to check if a set is a subset of another set in Python
The program is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
names = {"Devjeet","Ajit","Bulbul","Shawriya"}
toppers = {"Ajit","Bulbul"}
if toppers.issubset(names):
print("The toppers are in the 'names' list.")
else:
print("The toppers are not in the 'names' list.")
The output of the program is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
The toppers are in the 'names' list.
Few important tips about the program
1. The issubset() method in Python helps us to check if a set is a subset of another set in Python.
2. The invoking subset is subject to be tested against the superset which is passed as an argument.
3. The return type of this method is Boolean.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Oct 13,2022