Python - Set issuperset() Method


Advertisements

The Python set issuperset() method is used to check whether all elements of specified set are present in the specified set or not. It returns true if all elements of specified set are present in the given set, else returns false. Please note that, this method can take iterable as an argument also.

Note: Set A is called superset of set B if all the elements of set B are present in set A. The below figure depicts two sets called A = {10, 20, 30, 40, 50, 60} and B = {10, 30, 60}. As all the elements of B are present in A, hence, A is called superset of B.

Superset

Syntax


set.issuperset(iterable)

Parameters

iterable Required. specify set or iterable which need to be compared with the given set.

Example:

In the below example, SetA is checked againt SetB, SetC, ListB and ListC for superset using python issuperset() method.

SetA = {10, 20, 30, 40, 50, 60}

SetB = {10, 30, 60}
SetC = {5, 10, 15, 20, 25}

ListB = [10, 30, 60]
ListC = [5, 10, 15, 20, 25]

print(SetA.issuperset(SetB))
print(SetA.issuperset(SetC))

print(SetA.issuperset(ListB))
print(SetA.issuperset(ListC))

Output

True
False

True
False

Sets Methods




Advertisements