Set operations in Python
Membership math: unions, intersections, and differences.
backend = {"sam", "alex", "rio"}
frontend = {"rio", "kim", "sam"}
both = backend & frontend
everyone = backend | frontend
only_backend = backend - frontend
one_side = backend ^ frontend
frontend.add("noor")
frontend.discard("kim")
is_core = "sam" in both
overlap = backend.issubset(everyone)
How it works
&,|,-, and^combine two teams of names.addanddiscardedit a set in place.inandissubsetanswer membership questions.
The run, in numbers
- Lines
- 13
- Characters to type
- 294
- Tokens
- 81
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 54 seconds.
Step 2 of 10 in Collections, step 24 of 72 in Language basics.