typestar

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

  1. &, |, -, and ^ combine two teams of names.
  2. add and discard edit a set in place.
  3. in and issubset answer 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.

Type this snippet

Step 2 of 10 in Collections, step 24 of 72 in Language basics.

← Previous Next →