issubset(other) returns True when every item of the set is also found in other, and False if even one item is missing. Neither collection is changed.
The two collections may be equal: a set is a subset of itself. The argument can be any iterable, but a set on the other side keeps the check fast.
set.issubset() is an instance method of the built-in set type: call it on a set with dot notation, such as required.issubset(...). No import is needed.
Syntax
Call it on the smaller group, pass the bigger one, and use the returned True or False.
python
is_inside = s.issubset(iterable)
is_inside = s <= other_set
is_proper = s < other_set
Call
What it does
{1, 2}.issubset({1, 2, 3})
Returns True: both 1 and 2 are in the argument.
{1, 4}.issubset([1, 2, 3])
Returns False: 4 is not in the list.
set().issubset({1})
Returns True: the empty set is a subset of every set.
a <= b is the operator form and needs sets on both sides. a < b asks for a proper subset, which also requires b to have at least one extra item. For the opposite direction, use issuperset().
Method signatures
python
set.issubset(other)
# returns: True if every item of the set is also in other, otherwise False
# raises: TypeError if other is not iterable
Parameters
Parameter
Description
other
Any iterable to look inside: set, list, tuple, string, range, and so on. It is required: issubset() with no argument raises TypeError.
Return Value
Return Value
Description
bool
True if every item of the set is in other (including when they are equal); False otherwise.
Python Examples
Example 1 — Check a Candidate Has All the Required Skills
Test whether the required skills fit inside what each candidate knows.
All requirements met. Python and SQL are both in the candidate's skills, so the answer is True.
One is missing. The intern has Python but not SQL, so required.issubset(intern) is False.
Direction matters. The intern's skills are not all in the candidate's set, because "html" is missing, so the last test is False as well.
Example 2 — Compare issubset() With<= and <
See how equal sets and a bigger set behave with the method and with both operators.
python
small = {1, 2}
same = {2, 1}
big = {1, 2, 3}
print(small.issubset(same), small <= same, small < same)
print(small.issubset(big), small <= big, small < big)
print(big.issubset(small))
Output
True True False
True True True
False
How It Works
Equal sets. A set is a subset of an equal set, so the method and <= are True, but < is False because there is no extra item.
A real subset. The set {1, 2} fits inside {1, 2, 3} with one item to spare, so all three tests are True.
The reverse is false. {1, 2, 3} has an item that {1, 2} lacks, so big.issubset(small) is False.
Example 3 — Validate Typed Letters Against an Alphabet
Use sets built from strings and pass a string or list straight to the method.