A security check tests whether granted permissions overlap with forbidden permissions.
What You Need to Understand
set.isdisjoint(other) returns true if two collections have no common members. The supplied other argument can be any iterable.
When to Use It
A security check tests whether granted permissions overlap with forbidden permissions.
Step-by-Step Python Example
granted = {"read", "write"}
forbidden = {"delete", "admin"}
print(granted.isdisjoint(forbidden))
print(granted.isdisjoint({"write"}))
How the Example Works
The first result is true because no prohibited permission appears; the second is false due to write.
Example Output
True
False
True
A Second Example
Compare this smaller variation with the main example, then experiment with your own values.
print({1, 2}.isdisjoint({3, 4}))
Important Behavior and Edge Cases
Disjointness is symmetric and also true when either side is empty. It does not mean that both sets are empty.
Try It Yourself
Check whether two sets of product IDs overlap.
Common Beginner Mistakes
- Disjointness is symmetric and also true when either side is empty. It does not mean that both sets are empty.
- Using the wrong collection method for this operation without checking whether it mutates the object, returns a result, or raises on missing data.
Key Takeaways
set.isdisjoint(other)returns true if two collections have no common members.- The first result is true because no prohibited permission appears; the second is false due to
write. - Disjointness is symmetric and also true when either side is empty.