Standardize a Dataset (Z-Score Normalization)
Difficulty: Medium · Concept: Probability & Statistics — Expectation, Variance, Covariance
A direct, higher-stakes application of Sample Mean and Variance: z-score normalization rescales every value to "how many standard deviations from the mean is this," . This is the standard feature-scaling step before training many models — gradient descent converges faster and more reliably when features share a common scale, and distance-based methods like K-Means or KNN give distorted results if one feature's raw scale dwarfs another's.
The genuine edge case: standardization is undefined when a dataset has zero variance (every value identical) — dividing by a standard deviation of 0 has no sensible answer, and a real implementation needs to fail loudly rather than produce inf/nan silently.
Your task: implement standardize(data), returning a list of z-scores the same length as data. Raise ValueError if the data has zero variance.