The set.issuperset(other) method returns True if the calling set contains every element present in the specified iterable. If even one element of the target iterable is absent from the caller, it returns False.
Related Set Operations: For the reverse relationship, use issubset(). To test whether two collections share no common elements, use isdisjoint(). You can also evaluate set containment using the >= operator for supersets or > for strict proper supersets (accepting set instances only). CPython implements early short-circuiting: as soon as an item is found missing in the caller, iteration halts immediately and returns False.
The standard CPython signature for set.issuperset() is defined as:
set_instance.issuperset(other)
| Component | Type | Required? | Behavior & Description |
|---|---|---|---|
other |
Iterable[Hashable] |
Yes (exactly one) | The target collection (set, list, tuple, dict keys, or generator) whose members must all exist in the caller set. |
| Return Value | bool |
— | Returns True if every element in other is present in the calling set; otherwise False. |
| Best-Case Time | O(1) | — | Short-circuits immediately when the first inspected item in other is missing from the caller set. |
| Worst-Case Time | O(len(other)) | — | When the caller is a true superset, every element in other is verified against the caller set. |
| Auxiliary Space | O(1) | — | Zero memory allocations; membership checks occur directly against existing hash tables. |
Evaluating supersets checks whether the calling container encompasses all items of another collection.
When set A contains every element present in set B, A.issuperset(B) evaluates to True:
A = {'x', 'y', 'z', 'a', 'b', 'c'}
B = {'x', 'y', 'z'}
# Every element of B is present inside A
is_parent = A.issuperset(B)
print("Is A a superset of B?", is_parent)
Output:
Is A a superset of B? True
When set B contains elements that do not exist inside set A, A.issuperset(B) evaluates to False:
A = {'x', 'y', 'z', 'a', 'b', 'c'}
B = {'x', 'y', 'z', 'k', 'l', 'm'}
# 'k', 'l', 'm' are in B but absent from A → False
is_parent = A.issuperset(B)
print("Is A a superset of B?", is_parent)
Output:
Is A a superset of B? False
Python supports mathematical comparison operators for set superset testing. Understanding general supersets versus proper supersets is critical:
| Mechanism | Mathematical Meaning | Condition When A == B | Allowed Argument Types |
|---|---|---|---|
A.issuperset(B) |
A ⊇ B (Superset) | True | Any Iterable (lists, tuples, dicts, strings) |
A >= B |
A ⊇ B (Superset) | True | Set instances only |
A > B |
A ⊃ B (Proper / Strict Superset) | False (A must be strictly larger than B) | Set instances only |
s1 = {1, 2, 3}
s2 = {1, 2, 3}
s3 = {1, 2}
print("s1 >= s2 (Equal sets are supersets): ", s1 >= s2) # True
print("s1 > s2 (Equal sets are NOT proper supersets):", s1 > s2) # False
print("s1 > s3 (s1 is strictly larger than s3): ", s1 > s3) # True
Output:
s1 >= s2 (Equal sets are supersets): True
s1 > s2 (Equal sets are NOT proper supersets): False
s1 > s3 (s1 is strictly larger than s3): True
Unlike comparison operators which mandate set operands, issuperset() can evaluate lists, tuples, dictionaries, and character strings directly.
Pass a list directly to check if all list items are included within the caller set:
active_features = {'x', 'y', 'a', 'b'}
required_flags = ['a', 'b']
print("Does active set encompass required flags?", active_features.issuperset(required_flags))
Output:
Does active set encompass required flags? True
When testing against a string, Python iterates over each individual character:
char_pool = {'y', 't', 'W', 'o', 'e'}
probe_str = 'We' # Checks 'W' and 'e'
print("Does pool contain all characters in 'We'?", char_pool.issuperset(probe_str))
# To test entire words, always wrap them in a container!
available_skills = {"python", "sql", "docker", "git"}
job_requirements = ["python", "sql"]
print("Does candidate satisfy job requirements? ", available_skills.issuperset(job_requirements))
Output:
Does pool contain all characters in 'We'? True
Does candidate satisfy job requirements? True
Before initializing a microservice, verify that the runtime environment includes all mandatory configuration keys and feature drivers:
def verify_system_environment(active_env_vars: set[str], required_manifest: set[str]) -> bool:
return active_env_vars.issuperset(required_manifest)
REQUIRED_CONFIGS = {"DATABASE_URL", "REDIS_HOST", "JWT_SECRET"}
prod_env = {"DATABASE_URL", "REDIS_HOST", "JWT_SECRET", "DEBUG_MODE", "SENTRY_DSN"}
dev_env = {"DATABASE_URL", "DEBUG_MODE"}
print("Production env ready:", verify_system_environment(prod_env, REQUIRED_CONFIGS))
print("Development env ready:", verify_system_environment(dev_env, REQUIRED_CONFIGS))
Output:
Production env ready: True
Development env ready: False
Ensure a client's subscription plan is a superset of all capabilities needed to perform a requested workflow:
PLAN_TIERS = {
"starter": {"view_dashboard", "export_csv"},
"enterprise": {"view_dashboard", "export_csv", "custom_reports", "api_access", "sso_login"}
}
workflow_needs = {"export_csv", "api_access"}
print("Starter tier eligible: ", PLAN_TIERS["starter"].issuperset(workflow_needs))
print("Enterprise tier eligible:", PLAN_TIERS["enterprise"].issuperset(workflow_needs))
Output:
Starter tier eligible: False
Enterprise tier eligible: True
any_set.issuperset(set()) is always True:
print({1, 2}.issuperset(set())) # True
print(set().issuperset({1, 2})) # False (empty set cannot encompass elements)
print(set().issuperset(set())) # True (Ø ⊇ Ø)
>= operator strictly requires a set instance on the right-hand side. Passing a list raises a TypeError:
s = {1, 2, 3}
try:
result = s >= [1, 2]
except TypeError as e:
print("Operator error:", e) # unsupported operand type(s) for >=: 'set' and 'list'
Validate your understanding of superset behaviors across edge cases with this self-verifying test suite:
# Test 1: Reflexive property (every set is a superset of itself)
s = {10, 20, 30}
assert s.issuperset(s) is True
assert (s >= s) is True
assert (s > s) is False # Not a strict proper superset
# Test 2: Empty set target containment
assert s.issuperset(set()) is True
assert (s > set()) is True # Non-empty set is a proper superset of empty set
# Test 3: Heterogeneous iterables
assert {'a', 'b', 'c'}.issuperset(['a', 'b']) is True
assert {'a', 'b', 'c'}.issuperset(['a', 'z']) is False
# Test 4: Dictionary key evaluation
d = {"key1": 1, "key2": 2}
assert {"key1", "key2", "extra"}.issuperset(d) is True
assert {1, 2, 3}.issuperset(d) is False # Checks keys, not values
print("All set.issuperset assertions passed successfully!")
Output:
All set.issuperset assertions passed successfully!
Deepen your skills with live interactive examples, proper superset comparisons, and dependency verification drills in our companion notebook:
Explore interactive code cells, benchmark issuperset() vs. >=, and solve real-world pre-flight environment checks.
Tests whether every element of the calling set is contained within another collection (subset containment).
Tests whether two sets share zero common elements (zero shared elements).
Computes the set of common elements, returning a new set object.
Computes elements unique to the calling set, excluding items found in other iterables.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.