title: Python list subtraction
body: <p>This is the practice example :</p>
  
  <blockquote>
    <p>Write a function <code>(list1, list2)</code> that takes in two lists as arguments and return a list that is the result of removing elements from <code>list1</code> that can be found in <code>list2</code>.</p>
  </blockquote>
  
  <p>Why does this function return <code>[1, 3, 4]</code> and not <code>[4]</code> as I thought it would? I think it has something to do with <code>list1.remove()</code>. I guess it's something obvious, but I can't see it.</p>
  
  <p>It works on these examples:</p>
  
  <pre><code>subtractList (['a', 'b', 'c', 'd'], ['x', 'y', 'z']) =
      ['a', 'b', 'c', 'd']
  
  subtractList([1,2,3,4,5], [2, 4]) =
      [1, 3, 5]
  </code></pre>
  
  <p>but fails on this:</p>
  
  <pre><code>subtractList(range(5), range(4))
  </code></pre>
  
  <p>Also i noticed it removes only even numbers from the list.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>def subtractList(list1,list2):
      list1 = list(list1)
      list2 = list(list2)
  
      for i in list1:
          if i in list2:
              list1.remove(i)
  
      return list1
  </code></pre>
  
  <p>I have solved this practice with:</p>
  
  <pre><code>def subtractList(list1,list2):
  
      new_list = []
  
      list1 = list(list1)
      list2 = list(list2)
  
      for i in list1:
          if i not in list2:
              new_list.append(i)
  
      return new_list
  </code></pre>