Combinations
When order doesn't.
Choosing three friends for a team is different from ranking them. Ana, Ben, and Cara is the same team as Cara, Ben, and Ana. When the order doesn't matter, we count combinations.

- Pick a team of three
- Order doesn't matter
- Combinations
Choosing groups
Math dot comb counts the ways to choose K items from N. Choosing three from five gives ten teams, because each team was counted six times as a permutation. A lottery that picks six numbers from forty nine has nearly fourteen million combinations. Run it. One ticket gives you about a one in fourteen million chance.
import math
from itertools import combinations
print(math.comb(5, 3), "teams")
print(list(combinations("ABCDE", 3))[:3])
tickets = math.comb(49, 6)
print(f"lottery: {tickets:,} combinations")10 teams
[('A', 'B', 'C'), ('A', 'B', 'D'), ('A', 'B', 'E')]
lottery: 13,983,816 combinationsCounting in ML
Combinations explain why some problems explode. A model with forty features has over a trillion possible subsets of features, so you can't try them all. That's why we use smarter methods, like regularization, or greedy feature selection, instead of checking every combination.
| key | value |
|---|---|
| math.comb(n, k) | n! ÷ (k! (n−k)!) |
| 5 choose 3 | 10 |
| Lottery | 13,983,816 |
| 40 features | over a trillion subsets |
Summary
Combinations count groups where order doesn't matter. They grow very fast. Next, a quiz on probability.
Key takeaways- math.comb(n, k)
- Order doesn't matter
- They explode quickly