set.issubset()
Test set containment — is every element of self already in other?
Common call
required <= granted
Returns
True or False
Replaces
`all(x in other for x in self)` in one call
Watch out
empty set is a subset of ANY set — including empty (vacuous truth)
set.issubset(otherother — A single iterable — set, list, tuple, generator, string, dict (keys). issubset() 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'}.issubset({'1', '2', '3', '4'})
TypeError: 'object' object is not iterable
issubset returns True when every element of self also appears in other. Empty set is a subset of EVERY set — including itself and even other empty sets — because there is no element 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). issubset() accepts any iterable; the `<=` operator requires a set. |
Return value
bool — True if every element of self is contained in other. Empty set is a subset of every set (vacuously). The `<=` operator does the same thing, but requires sets on both sides.
Common patterns
Permission check
Every required permission must be present.
if required_perms <= granted_perms: allow()
Required fields present
Fold keys into sets and compare.
if required_fields <= set(payload.keys()): process(payload) else: missing = required_fields - set(payload.keys())
Test against any iterable
issubset accepts iterables; the operator does not.
required.issubset(open("granted.txt")) # streams the file
Examples
1. Proper subset
{1, 2} <= {1, 2, 3}
Returns
True2. Equal is subset
{1, 2, 3} <= {1, 2, 3}
Returns
True3. Missing element
{1, 2, 4} <= {1, 2, 3}
Returns
False4. Empty is universal
set() <= {1, 2, 3}
Returns
True5. Empty subset of empty
set() <= set()
Returns
True6. Iterable other
{1, 2}.issubset([1, 2, 3, 4])
Returns
True7. Strict subset
{1, 2} < {1, 2, 3}
Returns
True (strict, not equal)Pitfalls
1. set() is a subset of EVERYTHING — including set()
The vacuously-true case surprises everyone once. There is no element in the empty set that could fail the "every element is in other" test, so the answer is True.
Unexpected True
set().issubset(set())
True
Guard for empty
if a and a <= b: ... # non-trivial subset
both non-empty AND subset
2. issubset != strict subset
`a <= b` and `a.issubset(b)` allow equality. For strict subset use `a < b` (self is subset AND not equal to other).
Equal returns True
{1, 2, 3}.issubset({1, 2, 3})
True # equal counts
Strict operator
{1, 2, 3} < {1, 2, 3}
False
3. The `<=` operator requires sets on both sides
issubset() accepts any iterable. `<=` does NOT — it needs a set on both sides.
Type error
{1, 2} <= [1, 2, 3]
TypeError: '<=' not supported between instances of 'set' and 'list'
Method form
{1, 2}.issubset([1, 2, 3])
True
4. String iterables explode into characters
Same footgun as every other set method — a string passed as other is iterated as characters, so multi-char items in self will not match.
Char comparison
{"ab"}.issubset("abcd")
False # "ab" is not one of the chars
Wrap it
{"ab"}.issubset({"ab", "cd"})
True
When to use
Use it
- Permission / capability checks ("every required X is present")
- Validating required-fields presence
- Testing whether one collection is contained within another
- Composing with other set operations for readable filter logic
Reach for something else
- Strict subset needed → `<` operator
- Just testing overlap → set.isdisjoint (or `&` and check emptiness)
- Ordered containment → convert to sorted tuples and compare
- Very large sets where a linear all() check is more memory-efficient than materializing both as sets
Notes
Complexity
O(|self|) — hash table lookups into other
Return
bool — True or False
CPython impl
Objects/setobject.c :: set_issubset
Memory
No allocation for sets; other may be materialized into a temporary set if it is a plain iterable
Thread-safe
Safe against reads; not safe under concurrent writes to either input
FAQ
Same result, but issubset accepts any iterable and `<=` requires both sides to be sets. `<` is the STRICT subset (not equal). Method form is more flexible; operator form reads better in comparisons.
History
2.3
set type added; `<=` operator available immediately.
2.6
issubset() method accepts any iterable (not just sets).