title: Python Repeat loop iteration on exception, supply new values
body: <p>In my script, I have to hit an endpoint multiple times as there is a cap of the number of values that can be passed through. So I iterate through sublists which works. The problem is that there are times where a set of values in a sublist will be rejected by the endpoint, however, there is no way of knowing which ones will be rejected until I get the rejected list of values from the response. I can raise an exception in these scenarios, remove the invalid values, and hit the end point again (i.e. repeat the code in the exception as the first try).</p>
  <p>However, I was curious to know if there is a better approach to do this. Something along the lines of when iteration breaks, I restart the same iteration but this time with the new values supplied. What is best practice? See examples below:</p>
  <pre><code>#repeat code in exception with newly created sublist. this works but repeat code               
  for sublist in sublists:
      try:
          #supply sublist to endpoint
      except:
          #create new sublist with erroneous values removed
          #copy code in try here but supply new list
  
  
  #restart same iteration after rejected but with new values. this doesnt work, but is there a way to make it work?        
  i=0
  while i&lt;len(sublists):
      try:
          #supply sublists[i] to endpoint
      except:
          #create new sublist[i] with erroneous values removed
          #restart current iteration but this time with the newly created sublist[i]
          i=i
  </code></pre>