title: Maximum and minimum caps for list values in Python
body: <p>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.</p>
  
  <pre><code>oldList = [266, 40, -15, 13]
  
  newList = [255, 40, 0, 13]
  </code></pre>
  
  <p>Currently I'm doing</p>
  
  <pre><code>for i in range(len(oldList)):
      if oldList[i] &gt; 255:
          oldList[i] = 255
      if oldList[i] &lt; 0:
          oldList[i] = 0
  </code></pre>
  
  <p>or similarly with <code>newList.append(oldList[i])</code>.</p>
  
  <p>But there has to be a better way than that, right?</p>