all Python 3Sets (set)function
frozenset.isdisjoint
frozenset
True if the frozenset has no elements in common with the other set.
Syntax
f.isdisjoint(other)
Unlike not (f & other), isdisjoint builds no intermediate set and bails out at the first shared element, which matters on large inputs. Any iterable works as the argument, but a plain iterator gets consumed partially or fully in the process, so you cannot test it again. The empty set is disjoint from everything, itself included: frozenset().isdisjoint(frozenset()) is True.
Examples
print(frozenset({1, 2}).isdisjoint({3, 4})) # → True
print(frozenset({1, 2}).isdisjoint({2, 3})) # → False
print(frozenset({1, 2}).isdisjoint([3, 4, 5])) # → True
print(frozenset('rhythm').isdisjoint('aeiou')) # → True
print(frozenset({1, 2, 3}).isdisjoint(range(3, 6))) # → False
print(frozenset().isdisjoint({1, 2})) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy