Set Methods
isdisjoint()
Return True if two sets have no elements in common.
set.isdisjoint(other)
set.isdisjoint() checks whether the calling set and other have an empty intersection.
Returns True if they share zero elements, and False if they share at least one element.
Parameters
| Name | Description |
|---|---|
| other | An iterable to compare against. |
Returns
True if disjoint; otherwise False.
Try it
Run it and change it
evens = {2, 4, 6, 8}
odds = {1, 3, 5, 7}
primes = {2, 3, 5, 7}
print("Evens & Odds disjoint:", evens.isdisjoint(odds))
print("Evens & Primes disjoint:", evens.isdisjoint(primes))Worth knowing
- Short-circuiting: Returns
Falseimmediately upon finding the first shared item for high performance.