all Python 3Sets (set)function
set.isdisjoint
checking
True if the two sets have no elements in common (empty intersection).
Syntax
s.isdisjoint(other)
Cheaper than not (a & b): no intermediate set is built and the scan stops at the first shared element it finds. The argument may be any iterable, not just a set — the & operator refuses anything but a set. An empty set shares nothing with anything, so it is always disjoint.
Examples
print({1, 2}.isdisjoint({3, 4})) # → True
print({1, 2}.isdisjoint({2, 3})) # → False
print({1, 2}.isdisjoint([3, 4, 5])) # → True
print({1, 2}.isdisjoint(set())) # → True
print({'spam', 'ads'}.isdisjoint('hello world spam'.split())) # → False
print(not ({1, 2} & {2, 3})) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy