title: How to stop loop at limit, if limit is given. How to return new list with appended values?
body: <p>I am building a function that accepts four parameters: <code>xs(original list)</code>, <code>old</code>, <code>new</code>, and <code>limit=None</code>). Given a certain value (<code>old</code>) if the old number is in the list, replace it with new value and return a new list called <code>new_xs</code>.</p>
  
  <p>The fourth argument limit is an integer states the maximum number of replacements allowed. I need to only replace up    to the  first limit occurrences of <code>old</code> and leave the  rest unchanged. When <code>limit==None</code>, there's truly   no  limit (and  I replace all occurrences of <code>old</code>).<br>
  Negative or zero limit: no replacement</p>
  
  <p>Example input/output:</p>
  
  <pre><code>xs=[1,2,3,4,5]
  old= 2
  new=100
  new_xs=[1,100,3,4,5]
  
  
  def replace(xs, old, new, limit=None):
      new_xs=[]
      for num in range(len(xs)):
          if num==old:
              new_xs.append(new)
      return new_xs
  </code></pre>
  
  <p>I'm not sure how to make it stop at the limit, if there ever was a limit.</p>