Example:
tuple = ("python", "includehelp", 43, 54.23)
Check if a tuple is a subset of another tuple
In this article, we are given two tuples. And we need to create a Python program to check if a tuple is a subset of another tuple.
Input:
Tup1 = (4, 1, 6)
Tup2 = (2, 4, 8, 1, 6, 5)
Output:
true
This can be done by checking the presence of elements tup1 in tup2. And python provides multiple methods to check for the sam.
Method 1:
One method to solve the problem is by using the issubset() method which checks if one tuple is a subset of another subset.
Output:
Method 2:
Another method to solve the problem is by using all method to check if all elements of the 1st tuple are present in the 2nd tuple.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer