inspection

set.isdisjoint

Returns True if s and other share no elements. Accepts any iterable; there is no operator form.

s.isdisjoint(other)

Parameters

Parameter Purpose
other Any iterable to test against s
returns bool — True when the intersection is empty

Examples

>>> {1, 2}.isdisjoint({3, 4})
True

No common elements.

>>> {1, 2}.isdisjoint({2, 3})
False

Element 2 is shared.

>>> {1, 2}.isdisjoint([3, 4, 5])
True

Accepts any iterable, not only sets.

>>> set().isdisjoint({1, 2})
True

The empty set is disjoint from every set.

Gotcha

There is no & or | style operator for disjointness. isdisjoint is faster than 'not (a & b)' because it can short-circuit on the first shared element.

Related methods

← All Python set methods · List methods · list vs tuple vs set