runtime
404 / 500
question 404 NumPy Foundations · easy

Rescale ratings to 0–1

To compare films rated on different scales, a recommender rescales each list of scores so the lowest becomes 0 and the highest becomes 1. Write rescale(scores): return (score - lowest) / (highest - lowest) for every score. If every score is the same there is no range: return all zeros.

Functionrescale(scores)
scoresa list of numbers
Returnsa list of floats between 0 and 1; all 0.0 when the scores are equal; [] for no scores
Examples
callrescale([3.5, 2, 4.5, 5])returns[0.5, 0, 0.8333333333333334, 1]
callrescale([1, 3])returns[0, 1]
callrescale([])returns[]

Loading your progress…

Rescale ratings to 0–1 — Python practice · Runtime