set.issuperset()
Test set containment from the other side — does self contain every element of other?
Common call
granted >= required
Returns
True or False
Replaces
`all(x in self for x in other)` in one call
Watch out
any set is a superset of the empty set — including empty (vacuous truth)
set.issuperset(otherother — A single iterable — set, list, tuple, generator, string, dict (keys). issuperset() accepts any iterable; the `>=` operator requires a set.type: iterable · required)
→ bool
Demo
Live evaluation
Try:
Inputs
asetself (comma-separated)
bsetother (comma-separated)
Output
{'1', '2', '3', '4'}.issuperset({'1', '2'})
True
issuperset returns True when every element of other appears in self. Any set is a superset of the empty set — including empty itself — because there is no element in the empty set that could fail the check. Neither input is modified.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| other | iterable | yes | A single iterable — set, list, tuple, generator, string, dict (keys). issuperset() accepts any iterable; the `>=` operator requires a set. |
Return value
bool — True if every element of other is contained in self — the mirror direction of issubset. Any set is a superset of the empty set (vacuously). The `>=` operator does the same thing but requires sets on both sides.
Common patterns
Permission check from the granting side
Reads more naturally as "granted covers required".
if granted_perms >= required_perms: allow()
Whitelist check
Is the input a subset of what we accept? Same test from the other side.
if allowed_options >= set(user_selection): apply(user_selection)
Sanity check on a required-fields set
The dict must contain every required key.
if set(payload) >= required_fields: process(payload)
Examples
1. Proper superset
{1, 2, 3} >= {1, 2}
Returns
True2. Equal is superset
{1, 2, 3} >= {1, 2, 3}
Returns
True3. Missing element
{1, 2} >= {1, 2, 3}
Returns
False4. Universal empty
{1, 2, 3} >= set()
Returns
True5. Empty vs empty
set() >= set()
Returns
True6. Iterable other
{1, 2, 3, 4}.issuperset([1, 2])
Returns
True7. Strict superset
{1, 2, 3} > {1, 2}
Returns
True (strict, not equal)Pitfalls
1. Any set is a superset of set()
The mirror of issubset's vacuous case. There is no element in the empty other that could fail — so the answer is always True.
Unexpected True
{1, 2, 3}.issuperset(set())
True
Guard for empty
if other and self >= other: ... # non-trivial superset
other non-empty AND superset
2. issuperset != strict superset
`a >= b` and `a.issuperset(b)` allow equality. For strict superset use `a > b` (self is superset AND not equal to other).
Equal returns True
{1, 2, 3}.issuperset({1, 2, 3})
True # equal counts
Strict operator
{1, 2, 3} > {1, 2, 3}
False
3. The `>=` operator requires sets on both sides
issuperset() accepts any iterable. `>=` does NOT — it needs a set on both sides.
Type error
{1, 2, 3} >= [1, 2]
TypeError: '>=' not supported between instances of 'set' and 'list'
Method form
{1, 2, 3}.issuperset([1, 2])
True
4. Direction confusion — a >= b vs a <= b
issuperset is "self contains other". issubset is "self is contained in other". Same relation, different sides. Getting the sides backwards silently returns a different answer.
Wrong side
{1, 2}.issuperset({1, 2, 3}) # expected True?
False # {1,2} does not contain 3
Right side
{1, 2, 3}.issuperset({1, 2})
True
When to use
Use it
- "Do we have everything they need?" — permission or capability grants
- Whitelist / allow-list checks
- Required-fields presence tests
- Any "self contains all of other" predicate
Reach for something else
- Strict superset needed → `>` operator
- "No overlap at all" → set.isdisjoint
- Ordered containment → convert to sorted tuples and compare
- When issubset reads more naturally — pick the direction that matches the domain language
Notes
Complexity
O(|other|) — hash table lookups into self
Return
bool — True or False
CPython impl
Objects/setobject.c :: set_issuperset
Memory
No allocation for sets; other may be materialized if it is a plain iterable
Thread-safe
Safe against reads; not safe under concurrent writes to either input
FAQ
Direction. `a.issuperset(b)` asks "does a contain everything in b?"; `a.issubset(b)` asks "is a contained inside b?". Same relation from opposite sides. Pick whichever reads clearest for the domain.
History
2.3
set type added; `>=` operator available immediately.
2.6
issuperset() method accepts any iterable (not just sets).