w3resource logo

:

Python Exercises

Python Exercise: Issubset and Issuperset

Python sets: Exercise-10 with Solution

Write a Python program to test whether every element in s is in t and every element in t is in s.

Sample Solution:-

Python Code:

setx = set(["apple", "mango"])
sety = set(["mango", "orange"])
setz = set(["mango"])
issubset = setx <= sety
print(issubset)
issuperset = setx >= sety
print(issuperset)
issubset = setz <= sety
print(issubset)
issuperset = sety >= setz
print(issuperset)

Sample Output:

False                                                                                                         
False                                                                                                         
True                                                                                                          
True

Python Code Editor:

Improve this sample solution and post your code through Disqus