title: Using list as operand
body: <p>I am running into a problem when passing a list to a function. It appears to have a global effect on the list variable, but I did not declare it as global in my function. Can anyone tell me what's happening and how to work around it?</p>
  
  <pre><code>def a_Minus_b(a,b):
      for i in range(len(b)):
          print("a= ", a)
          if b[i] in a:
              a.remove(b[i])
      return a
  
  x = [1,2,3,4]
  a_Minus_b(x,x)
  a=  [1, 2, 3, 4]
  a=  [2, 3, 4]
  a=  [2, 4]
  </code></pre>
  
  <p>Error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
    File "&lt;pyshell#115&gt;", line 1, in &lt;module&gt;
      a_Minus_b(x,x)
    File "&lt;pyshell#112&gt;", line 4, in a_Minus_b
      if b[i] in a:
  IndexError: list index out of range
  </code></pre>