Set Operators Build Union And Difference
Set operators |, &, -, and ^ compose permission coverage checks directly, with union, intersection, difference, and issubset methods as named equivalents.
Code
required = {"login", "mfa", "audit"}
available = {"audit", "login", "reporting"}
# intersection &: members present on both sides
print("both:", sorted(required & available))
# union |: merged and deduplicated
print("either:", sorted(required | available))
# difference -: in required but not in available
print("missing:", sorted(required - available))
# symmetric difference ^: members belonging to exactly one side
print("one side only:", sorted(required ^ available))
# subset <=: whether required is fully covered by available
print("covered:", required <= available)
# each operator has a matching same-named method
print("methods agree:",
required.union(available) == required | available,
required.intersection(available) == required & available,
required.difference(available) == required - available,
required.issubset(available) == (required <= available))Output
Captured from a sandboxed run of this snippet in the build pipeline.
both: ['audit', 'login']
either: ['audit', 'login', 'mfa', 'reporting']
missing: ['mfa']
one side only: ['mfa', 'reporting']
covered: False
methods agree: True True True TrueUnder the hood
The code works entirely on top-level bindings: required, available.
What to watch for
- Nothing third-party is pulled in; the snippet is dependency-free.
Using it
Expect labeled output — both:, either:, missing: — when the file runs.
Key statements
available = {"audit", "login", "reporting"}
required = {"login", "mfa", "audit"}
Interactive Tools for This Topic
Argon2id Hash InfoEstimate Argon2id password-hash latency and memory usage, and check your parameters against OWASP 2024 minimum and recommended settings.bcrypt Cost EstimatorEstimate bcrypt cost factor latency and brute-force resistance, and get a recommended cost for your target hash time and attacker throughput.CORS Header Policy DebuggerSimulate browser CORS preflight and credential policies against server response headers to pinpoint blocked origins, methods, or headers and fix them.CSP Header BuilderBuild a Content-Security-Policy header from per-directive sources, skipping empty ones and rejecting a blanket wildcard.
FAQ
- Are there dependencies to manage?
- No. There are no dependencies to declare or install. Its state lives in module-level bindings: `required`, `available`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.