Back
+10 XP
Concept

Set Operations: Venn Diagrams via Code

Sets perform instant Venn diagram math: `&` for intersection (in both), `|` for union (in either), and `-` for difference.

python
front = {"html", "js", "css"}
back = {"python", "sql", "js"}
print(front & back)  # {'js'} (intersection)
print(front - back)  # {'html', 'css'} (only in front)

# 86. Set Operations: Venn Diagrams via Code Sets perform instant Venn diagram math: `&` for intersection (in both), `|` for union (in either), and `-` for difference: ```python front = {"html", "js", "css"} back = {"python", "sql", "js"} print(front & back) # {'js'} (intersection) print(front - back) # {'html', 'css'} (only in front) ``` Never write nested loops to check if an item in list A also exists in list B. Convert them to sets and use `&` for microsecond mathematical comparisons.

Checkpoint

Which operator finds elements that exist in BOTH sets (intersection)?

Practice

Given `a = {1, 2, 3}` and `b = {2, 3, 4}`, find elements present in both using `&`. Print the result.

Terminal
01
Tap code blocks below to assemble
Available Blocks