Set method

set.issuperset()

Returns True when this set contains every element of the other collection. Same as the >= operator for two sets.

IntermediateEvery example below runs in your browser. Change the code and press Run.

set.issuperset(other)

a.issuperset(b) is the mirror of set.issubset(): it asks whether a contains everything that is in b. Extra elements in a are fine.

Pick whichever reads more naturally. "Does my toolbox contain all these tools?" reads well as toolbox.issuperset(needed).

A set is a superset of itself. For "contains everything and at least one more", use the operator a > b.

Parameters

ParameterWhat it is
other
required
A set or other iterable whose elements must all be in this set.

Return value

True or False.

Examples

1Basic check

Pythoneditable
big = {1, 2, 3, 4}
print(big.issuperset({2, 3}))
print(big.issuperset({3, 5}))
print(big >= {1, 4})
Output
True
False
True

2Does a password use every kind of character?

Pythoneditable
import string
kinds = {"lower", "upper", "digit"}
for pw in ["sunny42", "Sunny42"]:
    found = set()
    for ch in pw:
        if ch in string.ascii_lowercase:
            found.add("lower")
        elif ch in string.ascii_uppercase:
            found.add("upper")
        elif ch in string.digits:
            found.add("digit")
    print(pw, found.issuperset(kinds))
Output
sunny42 False
Sunny42 True

3Superset vs proper superset

Pythoneditable
a = {1, 2, 3}
print(a.issuperset({1, 2, 3}))
print(a > {1, 2, 3})
print(a > {1, 2})
Output
True
False
True

Common mistakes

Using >= with a list

The operator needs two sets; the method accepts any iterable.

Pythoneditable
toolbox = {"hammer", "saw", "drill"}
needed = ["saw", "drill"]
print(toolbox.issuperset(needed))
try:
    toolbox >= needed
except TypeError:
    print("TypeError: >= needs two sets")
Output
True
TypeError: >= needs two sets

Questions people ask

What is the difference between issuperset() and issubset()?

They look from opposite sides: a.issuperset(b) is the same as b.issubset(a) when both are sets.

How do I check that a list contains all required values?

set(items).issuperset(required).

Spotted a mistake on this page? Tell us