
Tuples — ordered, immutable sequences.
coords = (10, 20) point = (3.14, 2.71, 1.41) coords[0] # 10 x, y = coords # unpacking
Use tuples for data that shouldn't change: coordinates, RGB values, database records.
Sets — unordered collections of unique values.
colors = {"red", "green", "blue"}
colors.add("yellow")
colors.remove("red")
"green" in colors # TrueSet operations:
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
a | b # union: {1,2,3,4,5,6}
a & b # intersection: {3,4}
a - b # difference: {1,2}
a ^ b # symmetric diff: {1,2,5,6}When to use sets: Removing duplicates from a list (list(set(my_list))), membership testing (sets are O(1) vs list O(n)).
Reference:
TaskLoco™ — The Sticky Note GOAT