Counting: Permutations
When order matters.
Many probability questions come down to counting. How many ways can five runners finish first, second, and third? When the order matters, we're counting permutations.

- Probability often means counting
- First, second, third
- Order matters: permutations
Arrangements
Three letters, A, B, and C, can be arranged in six ways. Iter tools lists them all. Five runners can finish in five factorial ways, which is a hundred and twenty. And math dot perm counts ways to fill just the top three places. Run it. Sixty ways.
import math
from itertools import permutations
print(["".join(p) for p in permutations("ABC")])
print("5 runners, all places:", math.factorial(5))
print("5 runners, top 3:", math.perm(5, 3))['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA'] 5 runners, all places: 120 5 runners, top 3: 60
Why it multiplies
For first place, there are five choices. Then four runners are left for second, and three for third. So five times four times three, which is sixty. Factorial, written with an exclamation mark, multiplies all the way down to one. Five factorial is five times four times three times two times one.
| key | value |
|---|---|
| Top 3 of 5 | 5 × 4 × 3 = 60 |
| n! | n × (n−1) × … × 1 |
| math.factorial | all arrangements |
| math.perm(n, k) | ordered picks |
Summary
Permutations count arrangements where order matters. Multiply the choices at each step. Next, combinations, when order doesn't matter.
Key takeaways- permutations()
- math.factorial
- math.perm(n, k)