All problems
Winsorize Percentile Bounds
Problem
Winsorize values by clipping them to the [lower, upper] quantiles. Quantiles use linear interpolation between order statistics at position q * (n - 1).
Return the clipped list; empty input returns [].
Hint
Find the interpolated quantile values first, then clamp every element into that range.
Test cases
case 1
in: [[1,2,3,4,5,6,7,8,9,10],0.1,0.9]
expected: [1.9,2,3,4,5,6,7,8,9,9.1]
case 2
in: [[1,2,3,4],0,1]
expected: [1,2,3,4]
case 3
in: [[5,5,5],0.1,0.9]
expected: [5,5,5]
case 4
in: [[],0.1,0.9]
expected: []
Starter codePython
def winsorize(values, lower, upper):
# Your code here
pass4 test cases · run your code against them in the editor