Python 3 reference · Set Methods
Python Set isdisjoint() Method
Return True if the set has no elements in common with another iterable.
Python 3 Since 3.0
Syntax
set.isdisjoint(other)
Parameters
| Parameter | Description |
|---|---|
other |
An iterable. |
Return value
True or False.
Examples
print({1, 2}.isdisjoint({3, 4}), {1, 2}.isdisjoint([2, 5]))
Output
True False
banned = {"spam", "scam"}
words = "great offer no scam".split()
print("clean" if banned.isdisjoint(words) else "flagged")
Output
flagged
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
set.intersection()· Return a new set with the elements common to this set and all others. The same as a & b.set.issubset()· Return True if every element of this set is also in the other. The same as a <= b.- Python Sets · tutorial