set.issubset()
set.issubset(other) bool · Updated March 15, 2026 · Set Methods The .issubset() method returns True if every element of the set is also in the specified iterable. It’s the mathematical way to ask “is this set completely contained within that one?” This operation doesn’t modify either set — it just reports the relationship between them.
Syntax
set.issubset(other)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
other | iterable | — | Any iterable to compare against. Elements don’t have to be sets themselves — the method converts other to a set internally. |
Returns
bool:Trueif all elements of the set are inother,Falseotherwise.
Examples
Basic usage
Check if one set is contained within another:
small = {1, 2, 3}
large = {1, 2, 3, 4, 5}
print(small.issubset(large))
# True
All elements of small (1, 2, 3) exist in large, so it’s a subset.
When it’s not a subset
If the set contains elements not in the other:
fruits = {"apple", "banana", "cherry"}
citrus = {"orange", "lemon"}
print(fruits.issubset(citrus))
# False
fruits has elements ("apple", "banana", "cherry") that don’t exist in citrus, so it’s not a subset.
With lists
You can check against any iterable, not just sets:
colors = {"red", "blue"}
palette = ["red", "blue", "green", "yellow"]
print(colors.issubset(palette))
# True
The method converts the list to a set internally for comparison.
Empty sets are always subsets
The empty set is a subset of every set — including other empty sets:
empty = set()
anything = {1, 2, 3}
print(empty.issubset(anything))
# True
print(anything.issubset(empty))
# False (unless both are empty)
This is mathematically sound: “every element of the empty set is in anything” is vacuously true.
A set is always a subset of itself
Every set is a subset (and superset) of itself:
numbers = {1, 2, 3}
print(numbers.issubset(numbers))
# True
print({1, 2}.issubset({1, 2, 3}))
# True
print({1, 2, 3}.issubset({1, 2}))
# False
Common Patterns
Checking user permissions
A common use is verifying that a user’s permissions are all contained within allowed permissions:
user_permissions = {"read", "write"}
admin_permissions = {"read", "write", "delete", "admin"}
required_for_action = {"read", "write"}
available = user_permissions
if available.issubset(admin_permissions):
print("User has valid permissions")
else:
print("User has some unauthorized permissions")
# User has valid permissions
if required_for_action.issubset(available):
print("User can perform the action")
else:
print("User lacks required permissions")
# User can perform the action
Validating input against allowed values
Ensure all input values come from an approved list:
allowed_tags = {"python", "javascript", "rust", "go"}
user_tags = {"python", "javascript"}
if user_tags.issubset(allowed_tags):
print("All tags are valid")
else:
print("Some tags are not allowed")
# All tags are valid
Filtering by category membership
Find which items belong to a specific category set:
prime_numbers = {2, 3, 5, 7, 11, 13}
small_primes = {2, 3, 5}
single_digit_primes = {2, 3, 5, 7}
print(small_primes.issubset(prime_numbers))
# True
print(single_digit_primes.issubset(prime_numbers))
# True (7 is prime)
Checking if all dependencies are installed
Verify that all required packages are available:
required = {"numpy", "pandas", "matplotlib"}
installed = {"numpy", "pandas", "scipy", "seaborn"}
missing = required - installed
if not required.issubset(installed):
print(f"Missing packages: {missing}")
else:
print("All required packages are installed")
# Missing packages: {'matplotlib'}
Performance
The .issubset() method has:
- Average case: O(len(set)) — Python compares each element in the set against the other collection
- Worst case: O(len(set) + len(other)) when converting
otherto a set
The method short-circuits — it returns False as soon as it finds an element not in other, making it efficient for both subset and non-subset cases.
See Also
- set::set.intersection() — returns elements common to both sets
- set::set.difference() — returns elements in the set but not in another
- set::set.copy() — creates a shallow copy of the set