I have a list of values and I'd like to set the maximum value of any element in the list to 255 and the minimum value to 0 while leaving those within the range unchanged.
oldList = [266, 40, -15, 13]
newList = [255, 40, 0, 13]
Currently I'm doing
for i in range(len(oldList)):
if oldList[i] > 255:
oldList[i] = 255
if oldList[i] < 0:
oldList[i] = 0
or similarly with newList.append(oldList[i])
.
But there has to be a better way than that, right?