Update a mean without storing all samples
A running average can be updated from its previous value and a count. When the next sample arrives, move the mean by one count-th of the difference between the sample and the old mean. The formula avoids retaining observations and is useful for streams. An empty stream has no average, so its result needs a separate contract.
mean, count = 10.0, 2
count += 1
mean += (16 - mean) / count
print(mean)Think before coding
The update is algebraically equivalent to total divided by count. Only the current mean and count are needed between samples. Returning each prefix average makes the evolution visible. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write running_means(values). Consume an iterable once and return the average after each sample. An empty iterable gives []. Use the incremental update rather than repeatedly summing earlier samples.
The explanation opens here once every check passes.