def variance(x): m = 0.0 for v in x: m += v m /= len(x) total = 0.0 for v in x: total += (v - m) * (v - m) return total / (len(x) - 1)