math and statistics

math has the functions you'd expect, plus a few that save you in interviews:

  • math.isclose(a, b) compares floats safely. 0.1 + 0.2 == 0.3 is False.
  • math.inf is bigger than any number. It's the standard start value when you look for a minimum: best = math.inf.
  • math.floor and math.ceil round down and up. int() rounds toward zero, so int(-2.5) is -2 but math.floor(-2.5) is -3. // also floors.
  • math.gcd, math.lcm, math.comb(n, k) (n choose k) and math.isqrt work on ints exactly, with no float rounding.

statistics covers the basics: mean, median and mode. median sorts the data and averages the middle two when the count is even, an edge case interviewers like to ask about.

Run it, then try statistics.mean([]) to see what an empty list does.