The issuperset method
The issuperset
method checks whether elements of a sequence are included in a set. The method returns a Boolean value - True
or False
. In the parameter, we specify the sequence with which we want to compare the elements of the set.
Syntax
set.issuperset(sequence)
Example
Let's check if the elements of the second set are included in the first using the issuperset
method:
st1 = {'a', 'b', 'c'}
st2 = {'e', 'g', 'a'}
res = st1.issuperset(st2)
print(res)
Result of code execution:
False
Example
Now let's check the occurrence of elements again using the issuperset
method:
st1 = {'a', 'b', 'c'}
st2 = {'a', 'b', 'c'}
res = st1.issuperset(st2)
print(res)
Result of code execution:
True
Example
Let's compare the elements of a list with the elements of a set:
st = {'a', 'b', 'c'}
lst = ['a', 'b', 'c']
res = st.issuperset(lst)
print(res)
Result of code execution:
True
Example
Now let's compare the elements of a tuple with a set:
st = {'a', 'b', 'c'}
tlp = ('a', 'b', 'c')
res = st.issuperset(tlp)
print(res)
Result of code execution:
True
Example
The issuperset
method also has a short form:
st1 = {'a', 'b', 'c'}
st2 = {'e', 'g', 'a'}
res = st1 >= st2
print(res)
Result of code execution:
False
See also
-
method
issubset
,
which checks the presence of elements of a set in a sequence -
method
difference
,
which returns the differences between sets -
method
intersection
,
which returns the intersection of sets -
method
symmetric_difference
,
which excludes common elements of a set and a sequence