Reducing complexity of following code
<p>What I wanted to do was to search in a list and remove a value .</p>

<p>So I wrote the following code</p>

<pre><code>for x in range(10):
   if x in list1:
      list1.remove(x)
</code></pre>

<p>Does this function of order ~ (n^2) since first it looks for the value and then it deletes and pushes the rest of the values backwards ??</p>

<p>Also is there a way to turn this in order n by using try/except</p>

<pre><code>try:
  for x in range(10):
    list1.remove(x)
except ValueError:
  # make it go back to next iteration 
</code></pre>
