Question
How to check if a tuple is a subset of another tuple in python ?
Solution
✔ Verified
Use Python’s all() function to test if every element of the first tuple exists in the second tuple.
Example:-
tuple1 = (1, 2, 3)
tuple2 = (5, 3, 2, 1, 4)
is_subset = all(item in tuple2 for item in tuple1)
print(is_subset) # True
Click here to download practice questions on
Python Tuple