Python set.isdisjoint() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
set method

Definition

isdisjoint(other) answers one question: do the set and other have nothing in common? It returns True if they share no item, and False as soon as it finds one that is shared.

Nothing is changed or built, so it is the cheapest way to test for an overlap. The argument can be any iterable, such as a list, a tuple, or a string.

set.isdisjoint() is an instance method of the built-in set type: call it on a set with dot notation, such as room_a.isdisjoint(...). No import is needed.

Syntax

Pass one iterable and use the returned True or False in a condition.

python
no_overlap = s.isdisjoint(iterable)
CallWhat it does
{1, 2}.isdisjoint({3, 4})Returns True: no item appears in both.
{1, 2}.isdisjoint([2, 5])Returns False: 2 is in both. Any iterable can be used.
set().isdisjoint({1})Returns True: an empty set shares nothing with anything.

a.isdisjoint(b) gives the same answer as not (a & b), but it stops at the first shared item and builds no new set. To see which items are shared, use intersection().

Method signatures
python
set.isdisjoint(other)
# returns: True if the set and other share no item, otherwise False
# raises: TypeError if other is not iterable

Parameters

ParameterDescription
otherAny iterable: set, list, tuple, string, range, dict (its keys), and so on. It is required: isdisjoint() with no argument raises TypeError.

Return Value

Return ValueDescription
boolTrue if the two collections have no item in common; False if at least one item is shared.

Python Examples

Example 1 — Check Two Meetings Do Not Overlap

Store the hours each room is busy and test whether bookings clash.

python
room_a = {9, 10, 11}
room_b = {12, 13}
room_c = {11, 12}

print(room_a.isdisjoint(room_b))
print(room_a.isdisjoint(room_c))
print(room_b.isdisjoint([14, 15]))

How It Works

  1. No clash. Room A uses hours 9 to 11 and room B uses 12 and 13, so they share nothing and the answer is True.
  2. A clash at 11. Room C also uses hour 11, so isdisjoint() finds a shared item and returns False.
  3. A list works too. The list [14, 15] has no hour in common with room B, so the answer is True.

Example 2 — Warn About Allergens in a Menu

Check each dish's ingredient list against a set of allergies.

python
allergies = {"peanut", "soy"}
dishes = {
    "pad thai": ["noodles", "peanut", "lime"],
    "salad": ["lettuce", "tomato"],
    "tofu bowl": ["rice", "soy", "ginger"],
}

for dish in sorted(dishes):
    if allergies.isdisjoint(dishes[dish]):
        print(dish, "is safe")
    else:
        print(dish, "contains an allergen")

How It Works

  1. Ingredients are lists. The argument does not have to be a set, so each ingredient list is passed in as it is.
  2. Safe means disjoint. Lettuce and tomato are not allergens, so the set and the list share nothing for the salad.
  3. One shared item is enough. Peanut in the pad thai and soy in the tofu bowl each make the answer False.
  4. Menu order. Looping over sorted(dishes) lists the dishes alphabetically.

Example 3 — Learn the Edge Cases of isdisjoint()

Test empty sets, a string argument, and a set against itself.

python
tags = {"a", "b"}
nothing = set()

print(tags.isdisjoint(nothing))
print(nothing.isdisjoint(nothing))
print(tags.isdisjoint("bcd"))
print(tags.isdisjoint("xyz"))
print(tags.isdisjoint(tags))

How It Works

  1. Empty shares nothing. With an empty argument there is no item that could overlap, so the answer is True.
  2. An empty set against itself. Two empty collections are disjoint as well, so the second line also prints True.
  3. A string is a row of letters. "bcd" contains "b", which is in the set, so the answer is False, while "xyz" shares no letter.
  4. A non-empty set overlaps itself. Every item is in both sides, so tags.isdisjoint(tags) is False.

Frequently Asked Questions

True if the set and the argument have no item in common, and False if at least one item is shared. It never changes either one.
Yes. It stops at the first shared item and does not build a new set, so it is faster and uses less memory.
Yes. Any iterable is accepted, such as a list, a tuple, a string, or a range, and only the set itself must be a set.
Yes. isdisjoint() returns True because there is no item that could be in both.
Use intersection() or the & operator. isdisjoint() only answers whether anything is shared, not what.

Next: set.issubset()

Return True if every item of the set is also in the other iterable.

issubset() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful