Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
superset
communitycreator

What is issuperset() in Python?

Mahnoor Zaheer

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The issuperset() method is a set function in Python that tells whether or not a set contains all the elements of another set.

Syntax


set1.issuperset(set2)

Parameter

The issuperset() function takes one parameter. This parameter is the set that is checked to see if all its elements are present in the other set, i.e., whether or not the other (outside) set is its superset.

Return value

The return value is True if the outside set is a superset of the argument set. Otherwise, the function returns False.

Code

In the example below, ‘X’ is the superset of both ‘Y’ and ‘Z’ but not the other way around. This is why the second example returns False.

It is to be noted that if two sets are equal (have all the same elements), they are considered supersets of each other, e.g., set ‘Y’ and ‘Z’ in the code below:

# sets
X = {1, 2, 3, 4, 5}
Y = {1, 2, 3}
Z = {1, 2, 3}

# X(superset or not) and Y
print("Is X super set of Y or not?", X.issuperset(Y))

# Y(superset or not) and X
print("Is Y super set of X or not?", Y.issuperset(X))

# Z(superset or not) and Y
print("Is Z super set of Y or not?", Z.issuperset(Y))
The syntax of issuperset() method in Python

RELATED TAGS

python
superset
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring