issuperset(other) returns True when the set contains every item of other, and False if even one is missing. Neither collection is changed.
It is the mirror image of issubset(). The two may be equal: a set is a superset of itself. The argument can be any iterable, such as a list of required items.
set.issuperset() is an instance method of the built-in set type: call it on a set with dot notation, such as admin.issuperset(...). No import is needed.
Syntax
Call it on the bigger group, pass the items you need, and use the returned True or False.
python
has_all = s.issuperset(iterable)
has_all = s >= other_set
is_proper = s > other_set
Call
What it does
{1, 2, 3}.issuperset({1, 2})
Returns True: the set contains both 1 and 2.
{1, 2}.issuperset([2, 3])
Returns False: 3 is missing from the set.
{1}.issuperset([])
Returns True: every set contains the empty collection.
a >= b is the operator form and needs sets on both sides. a > b asks for a proper superset, which also requires a to have at least one extra item.
Method signatures
python
set.issuperset(other)
# returns: True if the set contains every item of other, otherwise False
# raises: TypeError if other is not iterable
Parameters
Parameter
Description
other
Any iterable of items to look for: set, list, tuple, string, range, and so on. It is required: issuperset() with no argument raises TypeError.
Return Value
Return Value
Description
bool
True if the set contains every item of other (including when they are equal); False otherwise.
Python Examples
Example 1 — Check a Role Has Every Needed Permission
Test whether each role's permission set contains the permissions a task needs.
A list of needs. The recipe ingredients are lists, and issuperset() accepts them without any conversion.
Pancakes are possible. The pantry holds flour, egg, and milk, so the result is True and "ready" is printed.
The cake is not. Butter is not in the pantry, so the test fails and the else branch runs.
Name the gap. Subtracting the pantry from the recipe's items leaves exactly the missing ingredient, "butter".
Example 3 — Compare issuperset() With >= and >
See how equal sets, a smaller set, and an empty list behave with the method and the operators.
python
big = {1, 2, 3}
small = {1, 2}
twin = {3, 2, 1}
print(big.issuperset(small), big >= small, big > small)
print(big.issuperset(twin), big >= twin, big > twin)
print(small.issuperset(big))
print(big.issuperset([]))
Output
True True True
True True False
False
True
How It Works
A real superset. {1, 2, 3} holds everything in {1, 2} and one more item, so all three tests are True.
An equal set. The method and >= say True, but > is False because nothing extra is left over.
The reverse is false. {1, 2} lacks 3, so small.issuperset(big) is False.
Nothing needed. An empty list has no item that could be missing, so the answer is True.
Frequently Asked Questions
True if the set contains every item of the argument, and False if at least one item is missing. An equal set counts as a superset.
They are mirror images. a.issuperset(b) asks whether a contains all of b, while a.issubset(b) asks whether all of a is inside b.
Yes. Any iterable is accepted, so s.issuperset(["a", "b"]) is a quick way to check that several required items are present.
An empty collection has no item that could be missing, so every set contains it. Check for an empty required list separately if that matters.
Yes for two sets, but the >= operator needs sets on both sides. The method also accepts a list, tuple, or string.