def clip( number_list, clipNum ):# returns the clipped array based on the clipNum. Clipping an array is replacing all the numbers greater than the number provided to that number. So for example if the list is [3,17,5,9,1,11] and the clipNum is 8, returned array is [3,8,5,8,1,8]. So all numbers greater than the clipNumber (here 8) is replaced by the clipNum(which is 8 in this example). clipNum that takes a maximum value as an argument and changes any value in the list that is higher than the specified maximum value to be the same as the maximum value. This function could also be called “haircut”, in that it takes values that are too high, and cuts them down to the maximum allowable height. (Think of a scissor going through your hair and trimming the ones that are too long.)
Asked
Active
Viewed 806 times
-1
-
2Stack Overflow is not a code writing service - if you have tried to solve the problem yourself then please post your attempt and the specific issues you encountered, otherwise please attempt to solve this yourself. – Oliver.R Mar 25 '20 at 02:59
1 Answers
1
You could do this with list comp:
def clip(number_list : list, clipNum : int) -> list:
return [n if n <= clipNum else clipNum for n in number_list]
l = [3,17,5,9,1,11]
l_clip = clip(l,8)
print(l_clip)

Phillyclause89
- 674
- 4
- 12